]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/logger.cpp
Per-logstream loglevels.
[user/henk/code/inspircd.git] / src / logger.cpp
index 458dcf5e0b9169595a4c64ecb7388beb75a25d85..03c02fe09f9659a052e83260076229c19edf26f0 100644 (file)
  * 
  */
 
+void LogManager::CloseLogs()
+{
+       /*
+        * This doesn't remove logstreams from the map/vector etc, because if this is called, shit is hitting the fan
+        * and we're going down anyway - this just provides a "nice" way for logstreams to clean up. -- w
+        */
+       std::map<std::string, std::vector<LogStream *> >::iterator i;
+
+       while (LogStreams.begin() != LogStreams.end())
+       {
+               i = LogStreams.begin();
+
+               while (i->second.begin() != i->second.end())
+               {
+                       std::vector<LogStream *>::iterator it = i->second.begin();
+
+                       delete (*it);
+                       i->second.erase(it);
+               }
+
+               LogStreams.erase(i);
+       }
+}
+
 bool LogManager::AddLogType(const std::string &type, LogStream *l)
 {
        std::map<std::string, std::vector<LogStream *> >::iterator i = LogStreams.find(type);
@@ -55,12 +79,25 @@ bool LogManager::AddLogType(const std::string &type, LogStream *l)
                LogStreams[type] = v;
        }
 
+       if (type == "*")
+               GlobalLogStreams.push_back(l);
+
        return true;
 }
 
 bool LogManager::DelLogType(const std::string &type, LogStream *l)
 {
        std::map<std::string, std::vector<LogStream *> >::iterator i = LogStreams.find(type);
+       std::vector<LogStream *>::iterator gi = GlobalLogStreams.begin();
+
+       while (gi != GlobalLogStreams.end())
+       {
+               if ((*gi) == l)
+               {
+                       GlobalLogStreams.erase(gi);
+                       break;
+               }
+       }
 
        if (i != LogStreams.end())
        {
@@ -80,14 +117,44 @@ bool LogManager::DelLogType(const std::string &type, LogStream *l)
                                delete l;
                                return true;
                        }
+
+                       it++;
                }
        }
 
        return false;
 }
 
+void LogManager::Log(const std::string &type, int loglevel, const char *fmt, ...)
+{
+       if (Logging)
+               return;
+
+       va_list a;
+       static char buf[65536];
+
+       va_start(a, fmt);
+       vsnprintf(buf, 65536, fmt, a);
+       va_end(a);
+
+       this->Log(type, loglevel, std::string(buf));
+}
+
 void LogManager::Log(const std::string &type, int loglevel, const std::string &msg)
 {
+       if (Logging)
+               return;
+
+       Logging = true;
+
+       std::vector<LogStream *>::iterator gi = GlobalLogStreams.begin();
+
+       while (gi != GlobalLogStreams.end())
+       {
+               (*gi)->OnLog(loglevel, type, msg);
+               gi++;
+       }
+
        std::map<std::string, std::vector<LogStream *> >::iterator i = LogStreams.find(type);
 
        if (i != LogStreams.end())
@@ -96,14 +163,12 @@ void LogManager::Log(const std::string &type, int loglevel, const std::string &m
 
                while (it != i->second.end())
                {
-                       (*it)->OnLog(loglevel, msg);
+                       (*it)->OnLog(loglevel, type, msg);
+                       it++;
                }
-
-               return;
        }
 
-       // blurp, no handler for this type
-       return;
+       Logging = false;
 }