1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2007 InspIRCd Development Team
6 * See: http://www.inspircd.org/wiki/index.php/Credits
8 * This program is free but copyrighted software; see
9 * the file COPYING for details.
11 * ---------------------------------------------------
14 /* $Core: libIRCDfilelogger */
18 #include "socketengine.h"
19 #include "inspircd_se_config.h"
20 #include "filelogger.h"
22 FileLogger::FileLogger(InspIRCd* Instance, FILE* logfile)
23 : ServerInstance(Instance), log(logfile), writeops(0)
27 Instance->SE->NonBlocking(fileno(log));
33 bool FileLogger::Readable()
38 void FileLogger::HandleEvent(EventType, int)
42 ServerInstance->SE->DelFd(this);
45 void FileLogger::WriteLogLine(const std::string &line)
52 int written = fprintf(log,"%s",buffer.c_str());
56 if ((written >= 0) && (written < (int)buffer.length()))
58 buffer.erase(0, buffer.length());
59 ServerInstance->SE->AddFd(this);
61 else if (written == -1)
64 ServerInstance->SE->AddFd(this);
68 /* Wrote the whole buffer, and no need for write callback */
79 void FileLogger::Close()
83 ServerInstance->SE->Blocking(fileno(log));
86 fprintf(log,"%s",buffer.c_str());
89 ServerInstance->SE->DelFd(this);
99 FileLogger::~FileLogger()