/* * * (C) 2003-2013 Anope Team * Contact us at team@anope.org * * Please read COPYING and README for further details. * * Based on the original code of Epona by Lara. * Based on the original code of Services by Andy Church. * */ #ifndef LOGGER_H #define LOGGER_H #include "anope.h" #include "defs.h" enum LogType { /* Used whenever an administrator uses an administrative comand */ LOG_ADMIN, /* Used whenever an administrator overides something, such as adding * access to a channel where they don't have permission to. */ LOG_OVERRIDE, /* Any other command usage */ LOG_COMMAND, LOG_SERVER, LOG_CHANNEL, LOG_USER, LOG_MODULE, LOG_NORMAL, LOG_TERMINAL, LOG_RAWIO, LOG_DEBUG, LOG_DEBUG_2, LOG_DEBUG_3, LOG_DEBUG_4 }; struct LogFile { Anope::string filename; std::ofstream stream; LogFile(const Anope::string &name); Anope::string GetName() const; }; /* Represents a single log message */ class CoreExport Log { public: /* Bot that should log this message */ const BotInfo *bi; /* For commands, the user executing the command */ Anope::string nick; /* For commands, the user executing the command, but might not always exist */ const User *u; /* For commands, the account executing teh command, but will not always exist */ const NickCore *nc; /* For commands, the command being executed */ Command *c; /* Used for LOG_CHANNEL */ Channel *chan; /* For commands, the channel the command was executed on, will not always exist */ const ChannelInfo *ci; /* For LOG_SERVER */ Server *s; /* For LOG_MODULE */ Module *m; LogType type; Anope::string category; std::list sources; std::stringstream buf; Log(LogType type = LOG_NORMAL, const Anope::string &category = "", const BotInfo *bi = NULL); /* LOG_COMMAND/OVERRIDE/ADMIN */ Log(LogType type, CommandSource &source, Command *c, const ChannelInfo *ci = NULL); /* LOG_CHANNEL */ Log(const User *u, Channel *c, const Anope::string &category = ""); /* LOG_USER */ explicit Log(const User *u, const Anope::string &category = "", const BotInfo *bi = NULL); /* LOG_SERVER */ explicit Log(Server *s, const Anope::string &category = "", const BotInfo *bi = NULL); explicit Log(const BotInfo *b, const Anope::string &category = ""); Log(Module *m, const Anope::string &category = ""); ~Log(); Anope::string BuildPrefix() const; template Log &operator<<(T val) { this->buf << val; return *this; } }; /* Configured in the configuration file, actually does the message logging */ class CoreExport LogInfo { public: std::list targets; std::map logfiles; std::list sources; int log_age; std::list admin; std::list override; std::list commands; std::list servers; std::list users; std::list channels; std::list normal; bool raw_io; bool debug; LogInfo(int logage, bool rawio, bool debug); ~LogInfo(); void AddType(std::list &list, const Anope::string &type); bool HasType(LogType ltype, const Anope::string &type) const; /* Logs the message l if configured to */ void ProcessMessage(const Log *l); }; #endif // LOGGER_H