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);
29 static bool Logging = false;
31 if (loglevel < this->loglvl)
39 Logging = true; // this avoids (rare chance) loops with logging server IO on networks
41 snprintf(buf, MAXBUF, "\2%s\2: %s", type.c_str(), msg.c_str());
43 c->WriteChannelWithServ(ServerInstance->Config->ServerName, "PRIVMSG %s :%s", c->name.c_str(), buf);
44 ServerInstance->PI->SendChannelPrivmsg(c, 0, buf);
50 /* $ModDesc: Logs output to a channel instead of / as well as a file. */
52 class ModuleChanLog : public Module
55 std::vector<ChannelLogStream*> cls;
57 ModuleChanLog(InspIRCd* Me) : Module(Me)
59 Implementation eventlist[] = { I_OnRehash };
60 ServerInstance->Modules->Attach(eventlist, this, 1);
65 virtual ~ModuleChanLog()
67 std::vector<ChannelLogStream*>::iterator i;
68 while ((i = cls.begin()) != cls.end())
70 ServerInstance->Logs->DelLogStream(*i);
75 virtual void OnRehash(User *user, const std::string ¶meter)
77 ConfigReader Conf(ServerInstance);
79 /* Since the CloseLogs prior to this hook just wiped out our logstreams for us, we just need to wipe the vector. */
80 std::vector<ChannelLogStream*>().swap(cls);
81 int index, max = Conf.Enumerate("log");
84 for (index = 0; index < max; ++index)
86 std::string method = Conf.ReadValue("log", "method", index);
89 //if (method != "file")
92 std::string type = Conf.ReadValue("log", "type", index);
93 std::string level = Conf.ReadValue("log", "level", index);
94 int loglevel = DEFAULT;
99 ServerInstance->Config->debugging = true;
101 else if (level == "verbose")
105 else if (level == "default")
109 else if (level == "sparse")
113 else if (level == "none")
118 std::string target = Conf.ReadValue("log", "target", index);
119 ChannelLogStream* c = new ChannelLogStream(ServerInstance, loglevel, target);
120 ServerInstance->Logs->AddLogTypes(type, c, true);
125 virtual Version GetVersion()
127 return Version(1,2,0,1,VF_VENDOR,API_VERSION);
132 MODULE_INIT(ModuleChanLog)