summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorw00t <w00t@e03df62e-2008-0410-955e-edbf42e46eb7>2008-02-09 12:41:17 +0000
committerw00t <w00t@e03df62e-2008-0410-955e-edbf42e46eb7>2008-02-09 12:41:17 +0000
commitaf7e1a1ca8b36064593becf62b1a91468ad32237 (patch)
tree6d2bdd3f4522c7bff69306fb6d3aa2f488e38d9c /src
parentdb1c78986c8055f59b9bdf98a883dfbf3f4db6b9 (diff)
New logging implementation. Also write messages about InspIRCd::Log() being deprecated. Any takers on changing it all to use the new system? :P. STILL TODO: create <log> blocks in config, add a method called to 'cleanup' (or use destructor) of logstreams, add a method to logmanager to initiate destruction of all logstreams.
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@8858 e03df62e-2008-0410-955e-edbf42e46eb7
Diffstat (limited to 'src')
-rw-r--r--src/filelogger.cpp35
-rw-r--r--src/helperfuncs.cpp45
-rw-r--r--src/inspircd.cpp7
-rw-r--r--src/logger.cpp24
4 files changed, 65 insertions, 46 deletions
diff --git a/src/filelogger.cpp b/src/filelogger.cpp
index e22b4fdf4..0e50f628e 100644
--- a/src/filelogger.cpp
+++ b/src/filelogger.cpp
@@ -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());
+ }
+}
diff --git a/src/helperfuncs.cpp b/src/helperfuncs.cpp
index 3f60cac80..d274dd244 100644
--- a/src/helperfuncs.cpp
+++ b/src/helperfuncs.cpp
@@ -18,23 +18,12 @@
#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;
}
diff --git a/src/inspircd.cpp b/src/inspircd.cpp
index 29457ec97..ef656cca9 100644
--- a/src/inspircd.cpp
+++ b/src/inspircd.cpp
@@ -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()
diff --git a/src/logger.cpp b/src/logger.cpp
index 458dcf5e0..83a657216 100644
--- a/src/logger.cpp
+++ b/src/logger.cpp
@@ -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;
}