]> git.lizzy.rs Git - minetest.git/blobdiff - src/log.cpp
m_active_object_messages is used like a queue. Use std::queue instead of std::list...
[minetest.git] / src / log.cpp
index b3b3f3f1b03af6c17d3d3cd1e2b0f2fc1665fe10..e6d80db34e2a0a9747a3e34dc684f9b96a999fdf 100644 (file)
@@ -24,13 +24,28 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include <sstream>
 #include <algorithm>
 #include "threads.h"
+#include "jthread/jmutexautolock.h"
 #include "debug.h"
 #include "gettime.h"
 #include "porting.h"
 #include "config.h"
 
+// Connection
+std::ostream *dout_con_ptr = &dummyout;
+std::ostream *derr_con_ptr = &verbosestream;
+
+// Server
+std::ostream *dout_server_ptr = &infostream;
+std::ostream *derr_server_ptr = &errorstream;
+
+#ifndef SERVER
+// Client
+std::ostream *dout_client_ptr = &infostream;
+std::ostream *derr_client_ptr = &errorstream;
+#endif
+
 #ifdef __ANDROID__
-unsigned int android_log_level_mapping[] {
+unsigned int android_log_level_mapping[] {
                /* LMT_ERROR */   ANDROID_LOG_ERROR,
                /* LMT_ACTION */  ANDROID_LOG_WARN,
                /* LMT_INFO */    ANDROID_LOG_INFO,
@@ -38,7 +53,7 @@ unsigned int android_log_level_mapping[] {
        };
 #endif
 
-std::list<ILogOutput*> log_outputs[LMT_NUM_VALUES];
+std::vector<ILogOutput*> log_outputs[LMT_NUM_VALUES];
 std::map<threadid_t, std::string> log_threadnames;
 JMutex                            log_threadnamemutex;
 
@@ -62,7 +77,7 @@ void log_add_output_all_levs(ILogOutput *out)
 void log_remove_output(ILogOutput *out)
 {
        for(int i=0; i<LMT_NUM_VALUES; i++){
-               std::list<ILogOutput*>::iterator it =
+               std::vector<ILogOutput*>::iterator it =
                                std::find(log_outputs[i].begin(), log_outputs[i].end(), out);
                if(it != log_outputs[i].end())
                        log_outputs[i].erase(it);
@@ -71,33 +86,29 @@ void log_remove_output(ILogOutput *out)
 
 void log_set_lev_silence(enum LogMessageLevel lev, bool silence)
 {
-       log_threadnamemutex.Lock();
+       JMutexAutoLock lock(log_threadnamemutex);
 
-       for (std::list<ILogOutput *>::iterator
-                       it = log_outputs[lev].begin();
-                       it != log_outputs[lev].end();
-                       ++it) {
+       for (std::vector<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();
-       log_threadnamemutex.Lock();
+       JMutexAutoLock lock(log_threadnamemutex);
+
        log_threadnames[id] = name;
-       log_threadnamemutex.Unlock();
 }
 
 void log_deregister_thread()
 {
        threadid_t id = get_current_thread_id();
-       log_threadnamemutex.Lock();
+       JMutexAutoLock lock(log_threadnamemutex);
+
        log_threadnames.erase(id);
-       log_threadnamemutex.Unlock();
 }
 
 static std::string get_lev_string(enum LogMessageLevel lev)
@@ -119,7 +130,7 @@ static std::string get_lev_string(enum LogMessageLevel lev)
 
 void log_printline(enum LogMessageLevel lev, const std::string &text)
 {
-       log_threadnamemutex.Lock();
+       JMutexAutoLock lock(log_threadnamemutex);
        std::string threadname = "(unknown thread)";
        std::map<threadid_t, std::string>::const_iterator i;
        i = log_threadnames.find(get_current_thread_id());
@@ -127,9 +138,10 @@ void log_printline(enum LogMessageLevel lev, const std::string &text)
                threadname = i->second;
        std::string levelname = get_lev_string(lev);
        std::ostringstream os(std::ios_base::binary);
-       os<<getTimestamp()<<": "<<levelname<<"["<<threadname<<"]: "<<text;
-       for(std::list<ILogOutput*>::iterator i = log_outputs[lev].begin();
-                       i != log_outputs[lev].end(); i++){
+       os << getTimestamp() << ": " << levelname << "["<<threadname<<"]: " << text;
+
+       for(std::vector<ILogOutput*>::iterator i = log_outputs[lev].begin();
+                       i != log_outputs[lev].end(); i++) {
                ILogOutput *out = *i;
                if (out->silence)
                        continue;
@@ -138,7 +150,6 @@ void log_printline(enum LogMessageLevel lev, const std::string &text)
                out->printLog(os.str(), lev);
                out->printLog(lev, text);
        }
-       log_threadnamemutex.Unlock();
 }
 
 class Logbuf : public std::streambuf