Anope IRC Services  Version 2.0
logger.h
Go to the documentation of this file.
1 /*
2  *
3  * (C) 2003-2014 Anope Team
4  * Contact us at team@anope.org
5  *
6  * Please read COPYING and README for further details.
7  *
8  * Based on the original code of Epona by Lara.
9  * Based on the original code of Services by Andy Church.
10  *
11  */
12 
13 #ifndef LOGGER_H
14 #define LOGGER_H
15 
16 #include "anope.h"
17 #include "defs.h"
18 
19 enum LogType
20 {
21  /* Used whenever an administrator uses an administrative comand */
23  /* Used whenever an administrator overides something, such as adding
24  * access to a channel where they don't have permission to.
25  */
27  /* Any other command usage */
40 };
41 
42 struct LogFile
43 {
45  std::ofstream stream;
46 
47  LogFile(const Anope::string &name);
48  ~LogFile();
49  const Anope::string &GetName() const;
50 };
51 
52 /* Represents a single log message */
54 {
55  public:
56  /* Bot that should log this message */
58  /* For commands, the user executing the command, but might not always exist */
59  User *u;
60  /* For commands, the account executing the command, but will not always exist */
62  /* For commands, the command being executed */
64  /* For commands, the command source */
66  /* Used for LOG_CHANNEL */
68  /* For commands, the channel the command was executed on, will not always exist */
69  const ChannelInfo *ci;
70  /* For LOG_SERVER */
72  /* For LOG_MODULE */
76 
77  std::stringstream buf;
78 
79  Log(LogType type = LOG_NORMAL, const Anope::string &category = "", BotInfo *bi = NULL);
80 
81  /* LOG_COMMAND/OVERRIDE/ADMIN */
82  Log(LogType type, CommandSource &source, Command *c, ChannelInfo *ci = NULL);
83 
84  /* LOG_CHANNEL */
85  Log(User *u, Channel *c, const Anope::string &category = "");
86 
87  /* LOG_USER */
88  Log(User *u, const Anope::string &category = "", BotInfo *bi = NULL);
89 
90  /* LOG_SERVER */
91  Log(Server *s, const Anope::string &category = "", BotInfo *bi = NULL);
92 
93  Log(BotInfo *b, const Anope::string &category = "");
94 
95  Log(Module *m, const Anope::string &category = "", BotInfo *bi = NULL);
96 
97  ~Log();
98 
99  private:
100  Anope::string FormatSource() const;
101  Anope::string FormatCommand() const;
102 
103  public:
104  Anope::string BuildPrefix() const;
105 
106  template<typename T> Log &operator<<(T val)
107  {
108  this->buf << val;
109  return *this;
110  }
111 };
112 
113 /* Configured in the configuration file, actually does the message logging */
115 {
116  public:
118  std::vector<Anope::string> targets;
119  std::vector<LogFile *> logfiles;
120  int last_day;
121  std::vector<Anope::string> sources;
122  int log_age;
123  std::vector<Anope::string> admin;
124  std::vector<Anope::string> override;
125  std::vector<Anope::string> commands;
126  std::vector<Anope::string> servers;
127  std::vector<Anope::string> users;
128  std::vector<Anope::string> channels;
129  std::vector<Anope::string> normal;
130  bool raw_io;
131  bool debug;
132 
133  LogInfo(int logage, bool rawio, bool debug);
134 
135  ~LogInfo();
136 
137  void OpenLogFiles();
138 
139  bool HasType(LogType ltype, const Anope::string &type) const;
140 
141  /* Logs the message l if configured to */
142  void ProcessMessage(const Log *l);
143 };
144 
145 #endif // LOGGER_H
146 
Definition: bots.h:24
Definition: servers.h:42
NickCore * nc
Definition: logger.h:61
Command * c
Definition: logger.h:63
CommandSource * source
Definition: logger.h:65
std::vector< Anope::string > servers
Definition: logger.h:126
std::vector< Anope::string > targets
Definition: logger.h:118
bool raw_io
Definition: logger.h:130
Definition: users.h:34
std::vector< Anope::string > users
Definition: logger.h:127
std::vector< Anope::string > sources
Definition: logger.h:121
Server * s
Definition: logger.h:71
const Anope::string & GetName() const
Definition: logger.cpp:73
std::stringstream buf
Definition: logger.h:77
std::vector< LogFile * > logfiles
Definition: logger.h:119
Module * m
Definition: logger.h:73
std::vector< Anope::string > admin
Definition: logger.h:123
~LogFile()
Definition: logger.cpp:68
BotInfo * bot
Definition: logger.h:117
LogType
Definition: logger.h:19
std::vector< Anope::string > channels
Definition: logger.h:128
const ChannelInfo * ci
Definition: logger.h:69
LogFile(const Anope::string &name)
Definition: logger.cpp:64
std::vector< Anope::string > commands
Definition: logger.h:125
std::ofstream stream
Definition: logger.h:45
bool debug
Definition: logger.h:131
Log & operator<<(T val)
Definition: logger.h:106
Definition: logger.h:42
Anope::string filename
Definition: logger.h:44
std::vector< Anope::string > normal
Definition: logger.h:129
#define CoreExport
Definition: services.h:62
int last_day
Definition: logger.h:120
Anope::string category
Definition: logger.h:75
User * u
Definition: logger.h:59
Anope::string name
Definition: access.cpp:22
Definition: logger.h:53
LogType type
Definition: logger.h:74
int log_age
Definition: logger.h:122
BotInfo * bi
Definition: logger.h:57
Channel * chan
Definition: logger.h:67