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 bool LogManager::AddLogType(const std::string &type, LogStream *l)
47 std::map<std::string, std::vector<LogStream *> >::iterator i = LogStreams.find(type);
49 if (i != LogStreams.end())
50 i->second.push_back(l);
53 std::vector<LogStream *> v;
61 bool LogManager::DelLogType(const std::string &type, LogStream *l)
63 std::map<std::string, std::vector<LogStream *> >::iterator i = LogStreams.find(type);
65 if (i != LogStreams.end())
67 std::vector<LogStream *>::iterator it = i->second.begin();
69 while (it != i->second.end())
75 if (i->second.size() == 0)
89 void LogManager::Log(const std::string &type, int loglevel, const std::string &msg)
91 std::map<std::string, std::vector<LogStream *> >::iterator i = LogStreams.find(type);
93 if (i != LogStreams.end())
95 std::vector<LogStream *>::iterator it = i->second.begin();
97 while (it != i->second.end())
99 (*it)->OnLog(loglevel, msg);
105 // blurp, no handler for this type