X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Flogger.cpp;h=b9f9bae0b7c866795d0382b593524bd7807543ec;hb=f5b2265c2e6868431abbaa301aa1d64e8d49d8b0;hp=03960f4a1655188189e6bafe2178c2cae398bcc3;hpb=37d97550b147e0d14f6a9e279f8505b7d49c84bb;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/logger.cpp b/src/logger.cpp index 03960f4a1..b9f9bae0b 100644 --- a/src/logger.cpp +++ b/src/logger.cpp @@ -21,7 +21,6 @@ #include "inspircd.h" -#include "filelogger.h" /* * Suggested implementation... @@ -51,12 +50,11 @@ */ const char LogStream::LogHeader[] = - "Log started for " VERSION " (" REVISION ", " MODULE_INIT_STR ")" - " - compiled on " SYSTEM; + "Log started for " INSPIRCD_VERSION " (" MODULE_INIT_STR ")"; LogManager::LogManager() + : Logging(false) { - Logging = false; } LogManager::~LogManager() @@ -79,40 +77,40 @@ void LogManager::OpenFileLogs() { ConfigTag* tag = i->second; std::string method = tag->getString("method"); - if (method != "file") + if (!stdalgo::string::equalsci(method, "file")) { continue; } std::string type = tag->getString("type"); std::string level = tag->getString("level"); LogLevel loglevel = LOG_DEFAULT; - if (level == "rawio") + if (stdalgo::string::equalsci(level, "rawio")) { loglevel = LOG_RAWIO; ServerInstance->Config->RawLog = true; } - else if (level == "debug") + else if (stdalgo::string::equalsci(level, "debug")) { loglevel = LOG_DEBUG; } - else if (level == "verbose") + else if (stdalgo::string::equalsci(level, "verbose")) { loglevel = LOG_VERBOSE; } - else if (level == "default") + else if (stdalgo::string::equalsci(level, "default")) { loglevel = LOG_DEFAULT; } - else if (level == "sparse") + else if (stdalgo::string::equalsci(level, "sparse")) { loglevel = LOG_SPARSE; } - else if (level == "none") + else if (stdalgo::string::equalsci(level, "none")) { loglevel = LOG_NONE; } FileWriter* fw; - std::string target = tag->getString("target"); + std::string target = ServerInstance->Config->Paths.PrependLog(tag->getString("target")); std::map::iterator fwi = logmap.find(target); if (fwi == logmap.end()) { @@ -121,7 +119,7 @@ void LogManager::OpenFileLogs() struct tm *mytime = gmtime(&time); strftime(realtarget, sizeof(realtarget), target.c_str(), mytime); FILE* f = fopen(realtarget, "a"); - fw = new FileWriter(f); + fw = new FileWriter(f, tag->getUInt("flush", 20, 1, UINT_MAX)); logmap.insert(std::make_pair(target, fw)); } else @@ -208,10 +206,9 @@ void LogManager::DelLogStream(LogStream* l) { for (std::map >::iterator i = LogStreams.begin(); i != LogStreams.end(); ++i) { - std::vector::iterator it; - while ((it = std::find(i->second.begin(), i->second.end(), l)) != i->second.end()) + while (stdalgo::erase(i->second, l)) { - i->second.erase(it); + // Keep erasing while it exists } } @@ -237,11 +234,8 @@ bool LogManager::DelLogType(const std::string &type, LogStream *l) if (i != LogStreams.end()) { - std::vector::iterator it = std::find(i->second.begin(), i->second.end(), l); - - if (it != i->second.end()) + if (stdalgo::erase(i->second, l)) { - i->second.erase(it); if (i->second.size() == 0) { LogStreams.erase(i); @@ -293,7 +287,7 @@ void LogManager::Log(const std::string &type, LogLevel loglevel, const std::stri for (std::map >::iterator gi = GlobalLogStreams.begin(); gi != GlobalLogStreams.end(); ++gi) { - if (std::find(gi->second.begin(), gi->second.end(), type) != gi->second.end()) + if (stdalgo::isin(gi->second, type)) { continue; } @@ -314,8 +308,10 @@ void LogManager::Log(const std::string &type, LogLevel loglevel, const std::stri } -FileWriter::FileWriter(FILE* logfile) -: log(logfile), writeops(0) +FileWriter::FileWriter(FILE* logfile, unsigned int flushcount) + : log(logfile) + , flush(flushcount) + , writeops(0) { } @@ -327,7 +323,7 @@ void FileWriter::WriteLogLine(const std::string &line) // throw CoreException("FileWriter::WriteLogLine called with a closed logfile"); fputs(line.c_str(), log); - if (++writeops % 20 == 0) + if (++writeops % flush == 0) { fflush(log); }