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: libIRCDlogger */
19 * Suggested implementation...
21 * bool AddLogType(const std::string &type, enum loglevel, LogStream *)
22 * bool DelLogType(const std::string &type, LogStream *)
23 * Log(const std::string &type, enum loglevel, const std::string &msg)
24 * std::map<std::string, std::vector<LogStream *> > logstreams (holds a 'chain' of logstreams for each type that are all notified when a log happens)
28 * virtual void OnLog(enum loglevel, const std::string &msg)
31 * Modules create their own logstream types (core will create one for 'file logging' for example) and create instances of these logstream types
32 * and register interest in a certain logtype. Globbing is not here, with the exception of * - for all events.. loglevel is used to drop
33 * events that are of no interest to a logstream.
35 * When Log is called, the vector of logstreams for that type is iterated (along with the special vector for "*"), and all registered logstreams
36 * are called back ("OnLog" or whatever) to do whatever they like with the message. In the case of the core, this will write to a file.
37 * In the case of the module I plan to write (m_logtochannel or something), it will log to the channel(s) for that logstream, etc.
39 * NOTE: Somehow we have to let LogManager manage the non-blocking file streams and provide an interface to share them with various LogStreams,
40 * as, for example, a user may want to let 'KILL' and 'XLINE' snotices go to /home/ircd/inspircd/logs/operactions.log, or whatever. How
41 * can we accomplish this easily? I guess with a map of pre-loved logpaths, and a pointer of FILE *..
45 void LogManager::CloseLogs()
48 * This doesn't remove logstreams from the map/vector etc, because if this is called, shit is hitting the fan
49 * and we're going down anyway - this just provides a "nice" way for logstreams to clean up. -- w
51 std::map<std::string, std::vector<LogStream *> >::iterator i;
53 while (LogStreams.begin() != LogStreams.end())
55 i = LogStreams.begin();
57 while (i->second.begin() != i->second.end())
59 std::vector<LogStream *>::iterator it = i->second.begin();
69 bool LogManager::AddLogType(const std::string &type, LogStream *l)
71 std::map<std::string, std::vector<LogStream *> >::iterator i = LogStreams.find(type);
73 if (i != LogStreams.end())
74 i->second.push_back(l);
77 std::vector<LogStream *> v;
83 GlobalLogStreams.push_back(l);
88 bool LogManager::DelLogType(const std::string &type, LogStream *l)
90 std::map<std::string, std::vector<LogStream *> >::iterator i = LogStreams.find(type);
91 std::vector<LogStream *>::iterator gi = GlobalLogStreams.begin();
93 while (gi != GlobalLogStreams.end())
97 GlobalLogStreams.erase(gi);
102 if (i != LogStreams.end())
104 std::vector<LogStream *>::iterator it = i->second.begin();
106 while (it != i->second.end())
112 if (i->second.size() == 0)
128 void LogManager::Log(const std::string &type, int loglevel, const char *fmt, ...)
134 static char buf[65536];
137 vsnprintf(buf, 65536, fmt, a);
140 this->Log(type, loglevel, std::string(buf));
143 void LogManager::Log(const std::string &type, int loglevel, const std::string &msg)
150 std::vector<LogStream *>::iterator gi = GlobalLogStreams.begin();
152 while (gi != GlobalLogStreams.end())
154 (*gi)->OnLog(loglevel, type, msg);
158 std::map<std::string, std::vector<LogStream *> >::iterator i = LogStreams.find(type);
160 if (i != LogStreams.end())
162 std::vector<LogStream *>::iterator it = i->second.begin();
164 while (it != i->second.end())
166 (*it)->OnLog(loglevel, type, msg);