]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_chanlog.cpp
a0d3da4dcd8fbf2e7c0737547f7314b331f078ae
[user/henk/code/inspircd.git] / src / modules / m_chanlog.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2008 InspIRCd Development Team
6  * See: http://www.inspircd.org/wiki/index.php/Credits
7  *
8  * This program is free but copyrighted software; see
9  *            the file COPYING for details.
10  *
11  * ---------------------------------------------------
12  */
13
14 #include "inspircd.h"
15
16 class ChannelLogStream : public LogStream
17 {
18  private:
19         std::string channel;
20         
21  public:
22         ChannelLogStream(InspIRCd *Instance, const std::string &chan) : LogStream(Instance), channel(chan)
23         {
24         }
25                                                                 
26         virtual void OnLog(int loglevel, const std::string &type, const std::string &msg)
27         {
28                 Channel *c = ServerInstance->FindChan(channel);
29                 
30                 if (c)
31                 {
32                         // So this won't work remotely. Oh well.
33                         c->WriteChannelWithServ(ServerInstance->Config->ServerName, "PRIVMSG %s :\2%s\2: %s", c->name, type.c_str(), msg.c_str());
34                 }
35         }
36 };
37
38 /* $ModDesc: Logs output to a channel instead of / as well as a file. */
39
40 class ModuleChanLog : public Module
41 {
42  private:
43         InspIRCd *ServerInstance;
44         ChannelLogStream *l;
45  public:
46         ModuleChanLog(InspIRCd* Me) : Module(Me)
47         {
48                 l = new ChannelLogStream(Me, "#services");
49                 Me->Logs->AddLogType("*", l);
50         }
51         
52         virtual ~ModuleChanLog()
53         {
54                 delete l;
55         }
56         
57         virtual Version GetVersion()
58         {
59                 return Version(1,1,0,1,VF_VENDOR,API_VERSION);
60         }
61 };
62
63
64 MODULE_INIT(ModuleChanLog)
65