]> git.netwichtig.de Git - user/henk/code/inspircd.git/commitdiff
New logging implementation. Also write messages about InspIRCd::Log() being deprecate...
authorw00t <w00t@e03df62e-2008-0410-955e-edbf42e46eb7>
Sat, 9 Feb 2008 12:41:17 +0000 (12:41 +0000)
committerw00t <w00t@e03df62e-2008-0410-955e-edbf42e46eb7>
Sat, 9 Feb 2008 12:41:17 +0000 (12:41 +0000)
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@8858 e03df62e-2008-0410-955e-edbf42e46eb7

include/filelogger.h
include/inspircd.h
include/logger.h
src/filelogger.cpp
src/helperfuncs.cpp
src/inspircd.cpp
src/logger.cpp

index 77ca6f886bd788fa9fe45494d3156c4ebcd63a7a..8395f1c965b9bb22cfe7a279086eed6ddb7d40bd 100644 (file)
@@ -88,5 +88,17 @@ class CoreExport FileLogger : public EventHandler
        virtual ~FileLogger();
 };
 
+class CoreExport FileLogStream : public LogStream
+{
+ private:
+       FileLogger *f;
+ public:
+       FileLogStream(InspIRCd *Instance, FILE *f, const std::string &type) : LogStream(Instance, type)
+       {
+               this->f = new FileLogger(Instance, f);
+       }
+
+       virtual void OnLog(int loglevel, const std::string &msg);
+};
 
 #endif
index e8d5c9b8ecc802e4ad9497620fddcadf5231b49e..5f57619d55df82202daa8d3112188b7c8baf9bc8 100644 (file)
@@ -304,10 +304,6 @@ class CoreExport InspIRCd : public classbase
         */
        socklen_t length;
 
-       /** Nonblocking file writer
-        */
-       FileLogger* Logger;
-
        /** Time offset in seconds
         * This offset is added to all calls to Time(). Use SetTimeDelta() to update
         */
index 1e043f4f1537bd83ec1dec94c416b4160f4b310b..d32c3d1844e788b4cd9cd0e497ccbb1c12cc1fe4 100644 (file)
@@ -16,7 +16,7 @@
 
 class CoreExport LogStream : public classbase
 {
- private:
+ protected:
        InspIRCd *ServerInstance;
        std::string type;
  public:
@@ -26,7 +26,7 @@ class CoreExport LogStream : public classbase
                this->type = type;
        }
 
-       virtual void OnLog(int loglevel, const std::string &msg);
+       virtual void OnLog(int loglevel, const std::string &msg) { }
 };
 
 class CoreExport LogManager : public classbase
@@ -34,6 +34,7 @@ class CoreExport LogManager : public classbase
  private:
        InspIRCd *ServerInstance;
        std::map<std::string, std::vector<LogStream *> > LogStreams;
+       std::vector<LogStream *> GlobalLogStreams; //holds all logstreams with a type of *
  public:
        LogManager(InspIRCd *Instance)
        {
index e22b4fdf4729a17c1e95e87e846b0562605e6409..0e50f628e9877743cc639e81e8e8cc2e0bc5d89b 100644 (file)
@@ -101,3 +101,38 @@ FileLogger::~FileLogger()
        this->Close();
 }
 
+
+void FileLogStream::OnLog(int loglevel, const std::string &text)
+{
+       static char TIMESTR[26];
+       static time_t LAST = 0;
+
+       /* sanity check, just in case */
+       if (!ServerInstance->Config)
+               return;
+
+       /* If we were given -debug we output all messages, regardless of configured loglevel */
+       if ((loglevel < ServerInstance->Config->LogLevel) && !ServerInstance->Config->forcedebug)
+               return;
+
+       if (ServerInstance->Time() != LAST)
+       {
+               time_t local = ServerInstance->Time();
+               struct tm *timeinfo = localtime(&local);
+
+               strlcpy(TIMESTR,asctime(timeinfo),26);
+               TIMESTR[24] = ':';
+               LAST = ServerInstance->Time();
+       }
+
+       if (ServerInstance->Config->log_file && ServerInstance->Config->writelog)
+       {
+               std::string out = std::string(TIMESTR) + " " + text.c_str() + "\n";
+               this->f->WriteLogLine(out);
+       }
+
+       if (ServerInstance->Config->nofork)
+       {
+               printf("%s %s\n", TIMESTR, text.c_str());
+       }
+}
index 3f60cac80419acc443aab3e34f4bef9fe4bc03e8..d274dd2446557e8e62c74edafd65331cdff7f08c 100644 (file)
 #include "xline.h"
 #include "exitcodes.h"
 
-static char TIMESTR[26];
-static time_t LAST = 0;
-
 /** Log()
  *  Write a line of text `text' to the logfile (and stdout, if in nofork) if the level `level'
  *  is greater than the configured loglevel.
  */
 void InspIRCd::Log(int level, const char* text, ...)
 {
-       /* sanity check, just in case */
-       if (!this->Config || !this->Logger)
-               return;
-
-       /* Do this check again here so that we save pointless vsnprintf calls */
-       if ((level < Config->LogLevel) && !Config->forcedebug)
-               return;
-
        va_list argsPtr;
        char textbuffer[65536];
 
@@ -47,34 +36,8 @@ void InspIRCd::Log(int level, const char* text, ...)
 
 void InspIRCd::Log(int level, const std::string &text)
 {
-       /* sanity check, just in case */
-       if (!this->Config || !this->Logger)
-               return;
-
-       /* If we were given -debug we output all messages, regardless of configured loglevel */
-       if ((level < Config->LogLevel) && !Config->forcedebug)
-               return;
-
-       if (Time() != LAST)
-       {
-               time_t local = Time();
-               struct tm *timeinfo = localtime(&local);
-
-               strlcpy(TIMESTR,asctime(timeinfo),26);
-               TIMESTR[24] = ':';
-               LAST = Time();
-       }
-
-       if (Config->log_file && Config->writelog)
-       {
-               std::string out = std::string(TIMESTR) + " " + text.c_str() + "\n";
-               this->Logger->WriteLogLine(out);
-       }
-
-       if (Config->nofork)
-       {
-               printf("%s %s\n", TIMESTR, text.c_str());
-       }
+       this->Logs->Log("WARNING", DEFAULT, "Deprecated call to InspIRCd::Log()! - log message follows");
+       this->Logs->Log("DEPRECATED", level, text);
 }
 
 std::string InspIRCd::GetServerDescription(const char* servername)
@@ -358,11 +321,11 @@ bool InspIRCd::OpenLog(char**, int)
 
        if (!Config->log_file)
        {
-               this->Logger = NULL;
                return false;
        }
 
-       this->Logger = new FileLogger(this, Config->log_file);
+       FileLogStream *f = new FileLogStream(this, Config->log_file, "*");
+       this->Logs->AddLogType("*", f);
        return true;
 }
 
index 29457ec9780a827c5f03c0b7589c725b4dc2505a..ef656cca9dcc8652c00ba8523b24bcce2caf9192 100644 (file)
@@ -103,9 +103,7 @@ void InspIRCd::Cleanup()
        }
 
        /* Close logging */
-       if (this->Logger)
-               this->Logger->Close();
-
+       // XXX we need to add a method to terminate all logstreams.
 
        /* Cleanup Server Names */
        for(servernamelist::iterator itr = servernames.begin(); itr != servernames.end(); ++itr)
@@ -182,8 +180,7 @@ void InspIRCd::RehashUsersAndChans()
 
 void InspIRCd::CloseLog()
 {
-       if (this->Logger)
-               this->Logger->Close();
+       // XXX add a method to terminate all logstreams.
 }
 
 void InspIRCd::SetSignals()
index 458dcf5e0b9169595a4c64ecb7388beb75a25d85..83a65721679ae03cfb6c0eaafe5b008ce7be1377 100644 (file)
@@ -55,12 +55,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,6 +93,8 @@ bool LogManager::DelLogType(const std::string &type, LogStream *l)
                                delete l;
                                return true;
                        }
+
+                       it++;
                }
        }
 
@@ -97,11 +112,20 @@ void LogManager::Log(const std::string &type, int loglevel, const std::string &m
                while (it != i->second.end())
                {
                        (*it)->OnLog(loglevel, 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;
 }