X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Flogger.cpp;h=c9b1cf9e492a5bf8bc4f21c874b96078d2baec54;hb=a8878569083bfa4753e9e118adee0ed1da6a0325;hp=20235a826030ebc315d85a5e03de565e9003b470;hpb=e3df3b9d267cb3839db268ff6d0be389c45ebf6d;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/logger.cpp b/src/logger.cpp index 20235a826..c9b1cf9e4 100644 --- a/src/logger.cpp +++ b/src/logger.cpp @@ -2,8 +2,8 @@ * | Inspire Internet Relay Chat Daemon | * +------------------------------------+ * - * InspIRCd: (C) 2002-2008 InspIRCd Development Team - * See: http://www.inspircd.org/wiki/index.php/Credits + * InspIRCd: (C) 2002-2009 InspIRCd Development Team + * See: http://wiki.inspircd.org/Credits * * This program is free but copyrighted software; see * the file COPYING for details. @@ -11,8 +11,6 @@ * --------------------------------------------------- */ -/* $Core: libIRCDlogger */ - #include "inspircd.h" #include "filelogger.h" @@ -31,7 +29,7 @@ * * How it works: * Modules create their own logstream types (core will create one for 'file logging' for example) and create instances of these logstream types - * and register interest in a certain logtype. Globbing is not here, with the exception of * - for all events.. loglevel is used to drop + * and register interest in a certain logtype. Globbing is not here, with the exception of * - for all events.. loglevel is used to drop * events that are of no interest to a logstream. * * When Log is called, the vector of logstreams for that type is iterated (along with the special vector for "*"), and all registered logstreams @@ -41,19 +39,19 @@ * NOTE: Somehow we have to let LogManager manage the non-blocking file streams and provide an interface to share them with various LogStreams, * as, for example, a user may want to let 'KILL' and 'XLINE' snotices go to /home/ircd/inspircd/logs/operactions.log, or whatever. How * can we accomplish this easily? I guess with a map of pre-loved logpaths, and a pointer of FILE *.. - * + * */ void LogManager::SetupNoFork() { if (!noforkstream) { - FileWriter* fw = new FileWriter(ServerInstance, stdout); - noforkstream = new FileLogStream(ServerInstance, ServerInstance->Config->forcedebug ? DEBUG : ServerInstance->Config->LogLevel, fw); + FileWriter* fw = new FileWriter(stdout); + noforkstream = new FileLogStream(ServerInstance->Config->forcedebug ? DEBUG : DEFAULT, fw); } else { - noforkstream->ChangeLevel(ServerInstance->Config->forcedebug ? DEBUG : ServerInstance->Config->LogLevel); + noforkstream->ChangeLevel(ServerInstance->Config->forcedebug ? DEBUG : DEFAULT); } AddLogType("*", noforkstream, false); } @@ -70,18 +68,21 @@ void LogManager::OpenFileLogs() { return; } - ConfigReader* Conf = new ConfigReader(ServerInstance); + ConfigReader* Conf = new ConfigReader; std::map logmap; std::map::iterator i; - for (int index = 0; index < Conf->Enumerate("log"); ++index) + for (int index = 0;; ++index) { - std::string method = Conf->ReadValue("log", "method", index); + ConfigTag* tag = ServerInstance->Config->ConfValue("log", index); + if (!tag) + break; + std::string method = tag->getString("method"); if (method != "file") { continue; } - std::string type = Conf->ReadValue("log", "type", index); - std::string level = Conf->ReadValue("log", "level", index); + std::string type = tag->getString("type"); + std::string level = tag->getString("level"); int loglevel = DEFAULT; if (level == "debug" || ServerInstance->Config->forcedebug) { @@ -109,14 +110,14 @@ void LogManager::OpenFileLogs() if ((i = logmap.find(target)) == logmap.end()) { FILE* f = fopen(target.c_str(), "a"); - fw = new FileWriter(ServerInstance, f); + fw = new FileWriter(f); logmap.insert(std::make_pair(target, fw)); } else { fw = i->second; } - FileLogStream* fls = new FileLogStream(ServerInstance, loglevel, fw); + FileLogStream* fls = new FileLogStream(loglevel, fw); AddLogTypes(type, fls, true); } } @@ -330,64 +331,26 @@ void LogManager::Log(const std::string &type, int loglevel, const std::string &m } -FileWriter::FileWriter(InspIRCd* Instance, FILE* logfile) -: ServerInstance(Instance), log(logfile), writeops(0) -{ - if (log) - { - Instance->SE->NonBlocking(fileno(log)); - SetFd(fileno(log)); - buffer.clear(); - } -} - -bool FileWriter::Readable() +FileWriter::FileWriter(FILE* logfile) +: log(logfile), writeops(0) { - return false; } -void FileWriter::HandleEvent(EventType, int) +void FileWriter::HandleEvent(EventType ev, int) { - WriteLogLine(""); - if (log) - { - ServerInstance->SE->DelFd(this); - } } void FileWriter::WriteLogLine(const std::string &line) { - if (line.length()) - { - buffer.append(line); - } + if (log == NULL) + return; +// XXX: For now, just return. Don't throw an exception. It'd be nice to find out if this is happening, but I'm terrified of breaking so close to final release. -- w00t +// throw CoreException("FileWriter::WriteLogLine called with a closed logfile"); - if (log) + fprintf(log,"%s",line.c_str()); + if (writeops++ % 20) { - int written = fprintf(log,"%s",buffer.c_str()); -#ifdef WINDOWS - buffer.clear(); -#else - if ((written >= 0) && (written < (int)buffer.length())) - { - buffer.erase(0, buffer.length()); - ServerInstance->SE->AddFd(this); - } - else if (written == -1) - { - if (errno == EAGAIN) - ServerInstance->SE->AddFd(this); - } - else - { - /* Wrote the whole buffer, and no need for write callback */ - buffer.clear(); - } -#endif - if (writeops++ % 20) - { - fflush(log); - } + fflush(log); } } @@ -395,22 +358,10 @@ void FileWriter::Close() { if (log) { - ServerInstance->SE->Blocking(fileno(log)); - - if (buffer.size()) - { - fprintf(log,"%s",buffer.c_str()); - } - -#ifndef WINDOWS - ServerInstance->SE->DelFd(this); -#endif - fflush(log); fclose(log); + log = NULL; } - - buffer.clear(); } FileWriter::~FileWriter()