1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2008 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 FileLogStream::FileLogStream(InspIRCd *Instance, int loglevel, FileWriter *fw)
23 : LogStream(Instance, loglevel), f(fw)
25 ServerInstance->Logs->AddLoggerRef(f);
28 FileLogStream::~FileLogStream()
30 /* FileWriter is managed externally now */
31 ServerInstance->Logs->DelLoggerRef(f);
34 void FileLogStream::OnLog(int loglevel, const std::string &type, const std::string &text)
36 static char TIMESTR[26];
37 static time_t LAST = 0;
39 /* sanity check, just in case */
40 if (!ServerInstance->Config)
43 /* If we were given -debug we output all messages, regardless of configured loglevel */
44 if ((loglevel < this->loglvl) && !ServerInstance->Config->forcedebug)
49 if (ServerInstance->Time() != LAST)
51 time_t local = ServerInstance->Time();
52 struct tm *timeinfo = localtime(&local);
54 strlcpy(TIMESTR,asctime(timeinfo),26);
56 LAST = ServerInstance->Time();
59 std::string out = std::string(TIMESTR) + " " + text.c_str() + "\n";
60 this->f->WriteLogLine(out);