X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Flogger.cpp;h=e2baa4b8da4137b0434579b8b8a68a40a77865ad;hb=37fd031da06761c8a050105b55d73a8ab499fb74;hp=d40e366b45082515fcbf7442999d686f3c3fa844;hpb=43847ec9c7e1a195163eb4c529f1c92fd1ace0a4;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/logger.cpp b/src/logger.cpp index d40e366b4..e2baa4b8d 100644 --- a/src/logger.cpp +++ b/src/logger.cpp @@ -3,7 +3,7 @@ * +------------------------------------+ * * InspIRCd: (C) 2002-2009 InspIRCd Development Team - * See: http://www.inspircd.org/wiki/index.php/Credits + * See: http://wiki.inspircd.org/Credits * * This program is free but copyrighted software; see * the file COPYING for details. @@ -31,7 +31,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,15 +41,15 @@ * 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 : DEFAULT, fw); + FileWriter* fw = new FileWriter(stdout); + noforkstream = new FileLogStream(ServerInstance->Config->forcedebug ? DEBUG : DEFAULT, fw); } else { @@ -70,7 +70,7 @@ 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) @@ -109,14 +109,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,8 +330,8 @@ 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) +FileWriter::FileWriter(FILE* logfile) +: log(logfile), writeops(0) { } @@ -341,13 +341,15 @@ void FileWriter::HandleEvent(EventType ev, int) void FileWriter::WriteLogLine(const std::string &line) { - if (log) + 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"); + + fprintf(log,"%s",line.c_str()); + if (writeops++ % 20) { - fprintf(log,"%s",line.c_str()); - if (writeops++ % 20) - { - fflush(log); - } + fflush(log); } } @@ -357,10 +359,11 @@ void FileWriter::Close() { fflush(log); fclose(log); + log = NULL; } } FileWriter::~FileWriter() { + this->Close(); } -