]> 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 83a65721679ae03cfb6c0eaafe5b008ce7be1377..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);
@@ -101,8 +125,36 @@ bool LogManager::DelLogType(const std::string &type, LogStream *l)
        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())
@@ -111,23 +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;
-       }
-
-       std::vector<LogStream *>::iterator gi = GlobalLogStreams.begin();
-
-       while (gi != GlobalLogStreams.end())
-       {
-               (*gi)->OnLog(loglevel, msg);
-               gi++;
        }
 
-       // blurp, no handler for this type
-       return;
+       Logging = false;
 }