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 * ---------------------------------------------------
16 class ChannelLogStream : public LogStream
22 ChannelLogStream(InspIRCd *Instance, int loglevel, const std::string &chan) : LogStream(Instance, loglevel), channel(chan)
26 virtual void OnLog(int loglevel, const std::string &type, const std::string &msg)
28 Channel *c = ServerInstance->FindChan(channel);
30 if (loglevel < this->loglvl) return;
35 snprintf(buf, MAXBUF, "\2%s\2: %s", type.c_str(), msg.c_str());
37 c->WriteChannelWithServ(ServerInstance->Config->ServerName, "PRIVMSG %s :%s", c->name, buf);
38 ServerInstance->PI->SendChannelPrivmsg(c, 0, buf);
43 /* $ModDesc: Logs output to a channel instead of / as well as a file. */
45 class ModuleChanLog : public Module
48 std::vector<ChannelLogStream*> cls;
50 ModuleChanLog(InspIRCd* Me) : Module(Me)
54 virtual ~ModuleChanLog()
56 std::vector<ChannelLogStream*>::iterator i;
57 while ((i = cls.begin()) != cls.end())
59 ServerInstance->Logs->DelLogStream(*i);
64 virtual void OnReadConfig(ServerConfig* sc, ConfigReader* Conf)
66 /* Since the CloseLogs prior to this hook just wiped out our logstreams for us, we just need to wipe the vector. */
67 std::vector<ChannelLogStream*>().swap(cls);
68 int index, max = Conf->Enumerate("log");
71 for (index = 0; index < max; ++index)
73 std::string method = Conf->ReadValue("log", "method", index);
78 std::string type = Conf->ReadValue("log", "type", index);
79 std::string level = Conf->ReadValue("log", "level", index);
80 int loglevel = DEFAULT;
85 ServerInstance->Config->debugging = true;
87 else if (level == "verbose")
91 else if (level == "default")
95 else if (level == "sparse")
99 else if (level == "none")
104 std::string target = Conf->ReadValue("log", "target", index);
105 ChannelLogStream* c = new ChannelLogStream(ServerInstance, loglevel, target);
106 ServerInstance->Logs->AddLogTypes(type, c, true);
111 virtual Version GetVersion()
113 return Version(1,2,0,1,VF_VENDOR,API_VERSION);
118 MODULE_INIT(ModuleChanLog)