1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2010 InspIRCd Development Team
6 * See: http://wiki.inspircd.org/Credits
8 * This program is free but copyrighted software; see
9 * the file COPYING for details.
11 * ---------------------------------------------------
16 /* $ModDesc: Logs snomask output to channel(s). */
18 class ModuleChanLog : public Module
22 * Multimap so people can redirect a snomask to multiple channels.
24 std::multimap<char, std::string> logstreams;
28 Implementation eventlist[] = { I_OnRehash, I_OnSendSnotice };
29 ServerInstance->Modules->Attach(eventlist, this, 2);
34 virtual ~ModuleChanLog()
38 virtual void OnRehash(User *user)
46 for (int i = 0; i < MyConf.Enumerate("chanlog"); i++)
48 channel = MyConf.ReadValue("chanlog", "channel", i);
49 snomasks = MyConf.ReadValue("chanlog", "snomasks", i);
51 if (channel.empty() || snomasks.empty())
53 ServerInstance->Logs->Log("m_chanlog", DEFAULT, "Malformed chanlog tag, ignoring");
57 for (std::string::const_iterator it = snomasks.begin(); it != snomasks.end(); it++)
59 logstreams.insert(std::make_pair(*it, channel));
60 ServerInstance->Logs->Log("m_chanlog", DEFAULT, "Logging %c to %s", *it, channel.c_str());
66 virtual ModResult OnSendSnotice(char &sno, std::string &desc, const std::string &msg)
68 std::multimap<char, std::string>::const_iterator it = logstreams.find(sno);
71 if (it == logstreams.end())
72 return MOD_RES_PASSTHRU;
74 snprintf(buf, MAXBUF, "\2%s\2: %s", desc.c_str(), msg.c_str());
76 while (it != logstreams.end())
84 Channel *c = ServerInstance->FindChan(it->second);
87 c->WriteChannelWithServ(ServerInstance->Config->ServerName.c_str(), "PRIVMSG %s :%s", c->name.c_str(), buf);
88 ServerInstance->PI->SendChannelPrivmsg(c, 0, buf);
94 return MOD_RES_PASSTHRU;
97 virtual Version GetVersion()
99 return Version("Logs snomask output to channel(s).", VF_VENDOR);
104 MODULE_INIT(ModuleChanLog)
115 * This is for the "old" chanlog module which intercepted messages going to the logfile..
116 * I don't consider it all that useful, and it's quite dangerous if setup incorrectly, so
117 * this is defined out but left intact in case someone wants to develop it further someday.
119 * -- w00t (aug 23rd, 2008)
121 #define OLD_CHANLOG 0
124 class ChannelLogStream : public LogStream
130 ChannelLogStream(int loglevel, const std::string &chan) : LogStream(loglevel), channel(chan)
134 virtual void OnLog(int loglevel, const std::string &type, const std::string &msg)
136 Channel *c = ServerInstance->FindChan(channel);
137 static bool Logging = false;
139 if (loglevel < this->loglvl)
147 Logging = true; // this avoids (rare chance) loops with logging server IO on networks
149 snprintf(buf, MAXBUF, "\2%s\2: %s", type.c_str(), msg.c_str());
151 c->WriteChannelWithServ(ServerInstance->Config->ServerName.c_str(), "PRIVMSG %s :%s", c->name.c_str(), buf);
152 ServerInstance->PI->SendChannelPrivmsg(c, 0, buf);