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 printf("I got called\n");
31 if (loglevel < this->loglvl)
37 snprintf(buf, MAXBUF, "\2%s\2: %s", type.c_str(), msg.c_str());
39 c->WriteChannelWithServ(ServerInstance->Config->ServerName, "PRIVMSG %s :%s", c->name, buf);
40 ServerInstance->PI->SendChannelPrivmsg(c, 0, buf);
45 /* $ModDesc: Logs output to a channel instead of / as well as a file. */
47 class ModuleChanLog : public Module
50 std::vector<ChannelLogStream*> cls;
52 ModuleChanLog(InspIRCd* Me) : Module(Me)
56 virtual ~ModuleChanLog()
58 std::vector<ChannelLogStream*>::iterator i;
59 while ((i = cls.begin()) != cls.end())
61 ServerInstance->Logs->DelLogStream(*i);
66 virtual void OnReadConfig(ServerConfig* sc, ConfigReader* Conf)
68 /* Since the CloseLogs prior to this hook just wiped out our logstreams for us, we just need to wipe the vector. */
69 std::vector<ChannelLogStream*>().swap(cls);
70 int index, max = Conf->Enumerate("log");
73 for (index = 0; index < max; ++index)
75 std::string method = Conf->ReadValue("log", "method", index);
78 //if (method != "file")
81 std::string type = Conf->ReadValue("log", "type", index);
82 std::string level = Conf->ReadValue("log", "level", index);
83 int loglevel = DEFAULT;
88 ServerInstance->Config->debugging = true;
90 else if (level == "verbose")
94 else if (level == "default")
98 else if (level == "sparse")
102 else if (level == "none")
107 std::string target = Conf->ReadValue("log", "target", index);
109 printf("looking at tag with method: %s type: %s level: %s target: %s", method.c_str(), type.c_str(), level.c_str(), target.c_str());
111 ChannelLogStream* c = new ChannelLogStream(ServerInstance, loglevel, target);
112 ServerInstance->Logs->AddLogTypes(type, c, true);
117 virtual Version GetVersion()
119 return Version(1,2,0,1,VF_VENDOR,API_VERSION);
124 MODULE_INIT(ModuleChanLog)