]> git.lizzy.rs Git - dragonfireclient.git/blobdiff - src/log.cpp
Move hex.h to util/
[dragonfireclient.git] / src / log.cpp
index 527f544802966835b7d59968824e93b9e7f83b3f..85c827597eeae0fa10221a503a13dcc6c910a356 100644 (file)
@@ -26,6 +26,17 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "threads.h"
 #include "debug.h"
 #include "gettime.h"
+#include "porting.h"
+#include "config.h"
+
+#ifdef __ANDROID__
+unsigned int android_log_level_mapping[] = {
+               /* LMT_ERROR */   ANDROID_LOG_ERROR,
+               /* LMT_ACTION */  ANDROID_LOG_WARN,
+               /* LMT_INFO */    ANDROID_LOG_INFO,
+               /* LMT_VERBOSE */ ANDROID_LOG_VERBOSE
+       };
+#endif
 
 std::list<ILogOutput*> log_outputs[LMT_NUM_VALUES];
 std::map<threadid_t, std::string> log_threadnames;
@@ -58,6 +69,21 @@ void log_remove_output(ILogOutput *out)
        }
 }
 
+void log_set_lev_silence(enum LogMessageLevel lev, bool silence)
+{
+       log_threadnamemutex.Lock();
+
+       for (std::list<ILogOutput *>::iterator
+                       it = log_outputs[lev].begin();
+                       it != log_outputs[lev].end();
+                       ++it) {
+               ILogOutput *out = *it;
+               out->silence = silence;
+       }
+
+       log_threadnamemutex.Unlock();
+}
+
 void log_register_thread(const std::string &name)
 {
        threadid_t id = get_current_thread_id();
@@ -93,6 +119,7 @@ static std::string get_lev_string(enum LogMessageLevel lev)
 
 void log_printline(enum LogMessageLevel lev, const std::string &text)
 {
+       log_threadnamemutex.Lock();
        std::string threadname = "(unknown thread)";
        std::map<threadid_t, std::string>::const_iterator i;
        i = log_threadnames.find(get_current_thread_id());
@@ -104,10 +131,14 @@ void log_printline(enum LogMessageLevel lev, const std::string &text)
        for(std::list<ILogOutput*>::iterator i = log_outputs[lev].begin();
                        i != log_outputs[lev].end(); i++){
                ILogOutput *out = *i;
+               if (out->silence)
+                       continue;
+
                out->printLog(os.str());
                out->printLog(os.str(), lev);
                out->printLog(lev, text);
        }
+       log_threadnamemutex.Unlock();
 }
 
 class Logbuf : public std::streambuf
@@ -137,6 +168,9 @@ class Logbuf : public std::streambuf
        void printbuf()
        {
                log_printline(m_lev, m_buf);
+#ifdef __ANDROID__
+               __android_log_print(android_log_level_mapping[m_lev], PROJECT_NAME, "%s", m_buf.c_str());
+#endif
        }
 
        void bufchar(char c)