diff options
author | aquanight <aquanight@e03df62e-2008-0410-955e-edbf42e46eb7> | 2008-02-14 00:43:48 +0000 |
---|---|---|
committer | aquanight <aquanight@e03df62e-2008-0410-955e-edbf42e46eb7> | 2008-02-14 00:43:48 +0000 |
commit | f995b32ff4a570f3c35521e5d426286dd25c1c89 (patch) | |
tree | fac73998662b97f9c594da716fe32c8e3111ae79 /src/logger.cpp | |
parent | 0fed3a06d0f889dc9429f74fcfff9398d2f29add (diff) |
More <log> stuff
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@8928 e03df62e-2008-0410-955e-edbf42e46eb7
Diffstat (limited to 'src/logger.cpp')
-rw-r--r-- | src/logger.cpp | 106 |
1 files changed, 63 insertions, 43 deletions
diff --git a/src/logger.cpp b/src/logger.cpp index b8cd3b298..7b0fa1798 100644 --- a/src/logger.cpp +++ b/src/logger.cpp @@ -101,33 +101,21 @@ void LogManager::OpenFileLogs() 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()) + std::map<std::string, std::vector<LogStream*> >().swap(LogStreams); /* Clear it */ + std::vector<LogStream*>().swap(GlobalLogStreams); /* Clear it */ + for (std::map<LogStream*, int>::iterator i = AllLogStreams.begin(); i != AllLogStreams.end(); ++i) { - 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); + 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(); ++i) + for (FileLogMap::iterator it = FileLogs.begin(); it != FileLogs.end(); ++it) { delete it->first; } - FileLogMap().swap(FileLogs); /* Swap with empty map to clear */ + FileLogMap().swap(FileLogs); } bool LogManager::AddLogType(const std::string &type, LogStream *l) @@ -146,47 +134,79 @@ 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 + { + ++ai->second; + } + return true; } -bool LogManager::DelLogType(const std::string &type, LogStream *l) +void LogManager::DelLogStream(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()) + for (std::map<std::string, std::vector<LogStream*> >::iterator i = LogStreams.begin(); i != LogStreams.end(); ++i) { - if ((*gi) == l) + std::vector<LogStream*>::iterator it; + while ((it = std::find(i->second.begin(), i->second.end(), l)) != i->second.end()) { - GlobalLogStreams.erase(gi); - break; + if (it == i->second.end()) continue; + i->second.erase(it); } } + std::vector<LogStream *>::iterator gi = std::find(GlobalLogStreams.begin(), GlobalLogStreams.end(), l); + if (gi != GlobalLogStreams.end()) GlobalLogStreams.erase(gi); + std::map<LogStream*, int>::iterator ai = AllLogStreams.begin(); + if (ai == AllLogStreams.end()) return; /* Done. */ + delete ai->first; + AllLogStreams.erase(ai); +} + +bool LogManager::DelLogType(const std::string &type, LogStream *l) +{ + std::map<std::string, std::vector<LogStream *> >::iterator i = LogStreams.find(type); + if (type == "*") + { + std::vector<LogStream *>::iterator gi = std::find(GlobalLogStreams.begin(), GlobalLogStreams.end(), l); + if (gi != GlobalLogStreams.end()) GlobalLogStreams.erase(gi); + } if (i != LogStreams.end()) { - std::vector<LogStream *>::iterator it = i->second.begin(); + std::vector<LogStream *>::iterator it = std::find(i->second.begin(), i->second.end(), l); - while (it != i->second.end()) + if (it != i->second.end()) { - if (*it == l) + i->second.erase(it); + if (i->second.size() == 0) { - i->second.erase(it); - - if (i->second.size() == 0) - { - LogStreams.erase(i); - } - - delete l; - return true; + LogStreams.erase(i); } - - it++; } + else + { + return false; + } + } + else + { + return false; } - return false; + std::map<LogStream*, int>::iterator ai = AllLogStreams.find(l); + if (ai == AllLogStreams.end()) return true; + + if ((--ai->second) < 1) + { + AllLogStreams.erase(ai); + delete l; + } + + return true; } void LogManager::Log(const std::string &type, int loglevel, const char *fmt, ...) |