diff options
author | aquanight <aquanight@e03df62e-2008-0410-955e-edbf42e46eb7> | 2008-02-15 13:30:46 +0000 |
---|---|---|
committer | aquanight <aquanight@e03df62e-2008-0410-955e-edbf42e46eb7> | 2008-02-15 13:30:46 +0000 |
commit | 11f1f2126c3e1f1cb91f5d6e273eba2850ca61a8 (patch) | |
tree | 8bd6949852d761fe8976d4195af26653c3e702b8 /src/logger.cpp | |
parent | 7bd02d8a5dbac685d53a3f2aac9052c6ab5efa6e (diff) |
Make -nofork work properly with logging now.
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@8944 e03df62e-2008-0410-955e-edbf42e46eb7
Diffstat (limited to 'src/logger.cpp')
-rw-r--r-- | src/logger.cpp | 47 |
1 files changed, 29 insertions, 18 deletions
diff --git a/src/logger.cpp b/src/logger.cpp index 7b0fa1798..5c24a4451 100644 --- a/src/logger.cpp +++ b/src/logger.cpp @@ -44,8 +44,24 @@ * */ +void LogManager::SetupNoFork() +{ + if (!noforkstream) + { + FileWriter* fw = new FileWriter(ServerInstance, stdout); + noforkstream = new FileLogStream(ServerInstance, ServerInstance->Config->forcedebug ? DEBUG : ServerInstance->Config->LogLevel, fw); + } + else + { + noforkstream->ChangeLevel(ServerInstance->Config->forcedebug ? DEBUG : ServerInstance->Config->LogLevel); + } + AddLogType("*", noforkstream, false); +} + void LogManager::OpenFileLogs() { + if (ServerInstance->Config->nofork) SetupNoFork(); // Call this to reregister the nofork stream. + if (!ServerInstance->Config->writelog) return; // Skip rest of logfile opening if we are running -nolog. ConfigReader* Conf = new ConfigReader(ServerInstance); std::map<std::string, FileWriter*> logmap; std::map<std::string, FileWriter*>::iterator i; @@ -56,7 +72,7 @@ void LogManager::OpenFileLogs() std::string type = Conf->ReadValue("log", "type", index); std::string level = Conf->ReadValue("log", "level", index); int loglevel = DEFAULT; - if (level == "debug") + if (level == "debug" || ServerInstance->Config->forcedebug) { loglevel = DEBUG; ServerInstance->Config->debugging = true; @@ -94,7 +110,7 @@ void LogManager::OpenFileLogs() std::string tok; while (css.GetToken(tok)) { - AddLogType(tok, fls); + AddLogType(tok, fls, true); } } } @@ -108,17 +124,9 @@ void LogManager::CloseLogs() delete i->first; } std::map<LogStream*, int>().swap(AllLogStreams); /* And clear it */ - - /* Now close FileLoggers, for those logstreams that neglected to properly free their stuff. */ - for (FileLogMap::iterator it = FileLogs.begin(); it != FileLogs.end(); ++it) - { - delete it->first; - } - - FileLogMap().swap(FileLogs); } -bool LogManager::AddLogType(const std::string &type, LogStream *l) +bool LogManager::AddLogType(const std::string &type, LogStream *l, bool autoclose) { std::map<std::string, std::vector<LogStream *> >::iterator i = LogStreams.find(type); @@ -134,14 +142,17 @@ bool LogManager::AddLogType(const std::string &type, LogStream *l) if (type == "*") GlobalLogStreams.push_back(l); - std::map<LogStream*, int>::iterator ai = AllLogStreams.find(l); - if (ai == AllLogStreams.end()) - { - AllLogStreams.insert(std::make_pair(l, 1)); - } - else + if (autoclose) { - ++ai->second; + std::map<LogStream*, int>::iterator ai = AllLogStreams.find(l); + if (ai == AllLogStreams.end()) + { + AllLogStreams.insert(std::make_pair(l, 1)); + } + else + { + ++ai->second; + } } return true; |