]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/filelogger.cpp
Show IP of the user in the quit snomask [dKingston]
[user/henk/code/inspircd.git] / src / filelogger.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2009 InspIRCd Development Team
6  * See: http://wiki.inspircd.org/Credits
7  *
8  * This program is free but copyrighted software; see
9  *            the file COPYING for details.
10  *
11  * ---------------------------------------------------
12  */
13
14 /* $Core */
15
16 #include "inspircd.h"
17 #include <fstream>
18 #include "socketengine.h"
19 #include "filelogger.h"
20
21 FileLogStream::FileLogStream(int loglevel, FileWriter *fw)
22         : LogStream(loglevel), f(fw)
23 {
24         ServerInstance->Logs->AddLoggerRef(f);
25 }
26
27 FileLogStream::~FileLogStream()
28 {
29         /* FileWriter is managed externally now */
30         ServerInstance->Logs->DelLoggerRef(f);
31 }
32
33 void FileLogStream::OnLog(int loglevel, const std::string &type, const std::string &text)
34 {
35         static char TIMESTR[26];
36         static time_t LAST = 0;
37
38         if (loglevel < this->loglvl)
39         {
40                 return;
41         }
42
43         if (ServerInstance->Time() != LAST)
44         {
45                 time_t local = ServerInstance->Time();
46                 struct tm *timeinfo = localtime(&local);
47
48                 strlcpy(TIMESTR,asctime(timeinfo),26);
49                 TIMESTR[24] = ':';
50                 LAST = ServerInstance->Time();
51         }
52
53         std::string out = std::string(TIMESTR) + " " + text.c_str() + "\n";
54         this->f->WriteLogLine(out);
55 }