+#include "exceptions.h"
+#include "util/numeric.h"
+#include "log.h"
+
+#include <sstream>
+#include <iostream>
+#include <algorithm>
+#include <cerrno>
+#include <cstring>
+
+class StringBuffer : public std::streambuf {
+public:
+ StringBuffer() {}
+
+ int overflow(int c);
+ virtual void flush(const std::string &buf) = 0;
+ std::streamsize xsputn(const char *s, std::streamsize n);
+ void push_back(char c);
+
+private:
+ std::string buffer;
+};
+
+
+class LogBuffer : public StringBuffer {
+public:
+ LogBuffer(Logger &logger, LogLevel lev) :
+ logger(logger),
+ level(lev)
+ {}
+
+ void flush(const std::string &buffer);
+
+private:
+ Logger &logger;
+ LogLevel level;
+};
+
+
+class RawLogBuffer : public StringBuffer {
+public:
+ void flush(const std::string &buffer);
+};
+
+
+#ifdef __ANDROID__
+static unsigned int level_to_android[] = {
+ ANDROID_LOG_INFO, // LL_NONE
+ //ANDROID_LOG_FATAL,
+ ANDROID_LOG_ERROR, // LL_ERROR
+ ANDROID_LOG_WARN, // LL_WARNING
+ ANDROID_LOG_WARN, // LL_ACTION
+ //ANDROID_LOG_INFO,
+ ANDROID_LOG_DEBUG, // LL_INFO
+ ANDROID_LOG_VERBOSE, // LL_VERBOSE
+
+};
+#endif
+
+////
+//// Globals
+////
+
+Logger g_logger;
+
+StreamLogOutput stdout_output(std::cout);
+StreamLogOutput stderr_output(std::cerr);
+std::ostream null_stream(NULL);
+
+RawLogBuffer raw_buf;
+
+LogBuffer none_buf(g_logger, LL_NONE);
+LogBuffer error_buf(g_logger, LL_ERROR);
+LogBuffer warning_buf(g_logger, LL_WARNING);
+LogBuffer action_buf(g_logger, LL_ACTION);
+LogBuffer info_buf(g_logger, LL_INFO);
+LogBuffer verbose_buf(g_logger, LL_VERBOSE);