anope- supernets anope source code & configuration |
git clone git://git.acid.vegas/anope.git |
Log | Files | Refs | Archive | README |
logger.h (3263B)
1 /* 2 * 3 * (C) 2003-2022 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 #ifndef LOGGER_H 13 #define LOGGER_H 14 15 #include "anope.h" 16 #include "defs.h" 17 18 enum LogType 19 { 20 /* Used whenever an administrator uses an administrative command */ 21 LOG_ADMIN, 22 /* Used whenever an administrator overrides something, such as adding 23 * access to a channel where they don't have permission to. 24 */ 25 LOG_OVERRIDE, 26 /* Any other command usage */ 27 LOG_COMMAND, 28 LOG_SERVER, 29 LOG_CHANNEL, 30 LOG_USER, 31 LOG_MODULE, 32 LOG_NORMAL, 33 LOG_TERMINAL, 34 LOG_RAWIO, 35 LOG_DEBUG, 36 LOG_DEBUG_2, 37 LOG_DEBUG_3, 38 LOG_DEBUG_4 39 }; 40 41 struct LogFile 42 { 43 Anope::string filename; 44 std::ofstream stream; 45 46 LogFile(const Anope::string &name); 47 ~LogFile(); 48 const Anope::string &GetName() const; 49 }; 50 51 /* Represents a single log message */ 52 class CoreExport Log 53 { 54 public: 55 /* Bot that should log this message */ 56 BotInfo *bi; 57 /* For commands, the user executing the command, but might not always exist */ 58 User *u; 59 /* For commands, the account executing the command, but will not always exist */ 60 NickCore *nc; 61 /* For commands, the command being executed */ 62 Command *c; 63 /* For commands, the command source */ 64 CommandSource *source; 65 /* Used for LOG_CHANNEL */ 66 Channel *chan; 67 /* For commands, the channel the command was executed on, will not always exist */ 68 const ChannelInfo *ci; 69 /* For LOG_SERVER */ 70 Server *s; 71 /* For LOG_MODULE */ 72 Module *m; 73 LogType type; 74 Anope::string category; 75 76 std::stringstream buf; 77 78 Log(LogType type = LOG_NORMAL, const Anope::string &category = "", BotInfo *bi = NULL); 79 80 /* LOG_COMMAND/OVERRIDE/ADMIN */ 81 Log(LogType type, CommandSource &source, Command *c, ChannelInfo *ci = NULL); 82 83 /* LOG_CHANNEL */ 84 Log(User *u, Channel *c, const Anope::string &category = ""); 85 86 /* LOG_USER */ 87 Log(User *u, const Anope::string &category = "", BotInfo *bi = NULL); 88 89 /* LOG_SERVER */ 90 Log(Server *s, const Anope::string &category = "", BotInfo *bi = NULL); 91 92 Log(BotInfo *b, const Anope::string &category = ""); 93 94 Log(Module *m, const Anope::string &category = "", BotInfo *bi = NULL); 95 96 ~Log(); 97 98 private: 99 Anope::string FormatSource() const; 100 Anope::string FormatCommand() const; 101 102 public: 103 Anope::string BuildPrefix() const; 104 105 template<typename T> Log &operator<<(T val) 106 { 107 this->buf << val; 108 return *this; 109 } 110 }; 111 112 /* Configured in the configuration file, actually does the message logging */ 113 class CoreExport LogInfo 114 { 115 public: 116 BotInfo *bot; 117 std::vector<Anope::string> targets; 118 std::vector<LogFile *> logfiles; 119 int last_day; 120 std::vector<Anope::string> sources; 121 int log_age; 122 std::vector<Anope::string> admin; 123 std::vector<Anope::string> override; 124 std::vector<Anope::string> commands; 125 std::vector<Anope::string> servers; 126 std::vector<Anope::string> users; 127 std::vector<Anope::string> channels; 128 std::vector<Anope::string> normal; 129 bool raw_io; 130 bool debug; 131 132 LogInfo(int logage, bool rawio, bool debug); 133 134 ~LogInfo(); 135 136 void OpenLogFiles(); 137 138 bool HasType(LogType ltype, const Anope::string &type) const; 139 140 /* Logs the message l if configured to */ 141 void ProcessMessage(const Log *l); 142 }; 143 144 #endif // LOGGER_H