From 16ca76c2e7ab287e480185fbb03a0bb438351eda Mon Sep 17 00:00:00 2001 From: Adam Date: Mon, 23 Jan 2017 12:35:14 -0500 Subject: Make log system use newer format strings Also allow log messages to be translatable --- include/anope.h | 51 ++-- include/bots.h | 5 +- include/channels.h | 25 +- include/commands.h | 15 +- include/defs.h | 1 + include/event.h | 4 +- include/extensible.h | 6 +- include/logger.h | 243 ++++++++++------ include/modules.h | 4 + include/modules/dns.h | 2 +- include/modules/redis.h | 6 +- include/protocol.h | 3 +- include/serialize.h | 17 +- include/servers.h | 6 +- include/users.h | 11 +- modules/botserv/assign.cpp | 8 +- modules/botserv/autoassign.cpp | 2 +- modules/botserv/badwords.cpp | 13 +- modules/botserv/bot.cpp | 8 +- modules/botserv/control.cpp | 4 +- modules/botserv/kick.cpp | 25 +- modules/botserv/set.cpp | 2 +- modules/chanserv/access.cpp | 15 +- modules/chanserv/akick.cpp | 36 ++- modules/chanserv/ban.cpp | 4 +- modules/chanserv/clone.cpp | 3 +- modules/chanserv/drop.cpp | 3 +- modules/chanserv/enforce.cpp | 12 +- modules/chanserv/entrymsg.cpp | 13 +- modules/chanserv/flags.cpp | 18 +- modules/chanserv/getkey.cpp | 2 +- modules/chanserv/invite.cpp | 4 +- modules/chanserv/kick.cpp | 4 +- modules/chanserv/list.cpp | 6 +- modules/chanserv/log.cpp | 32 ++- modules/chanserv/main/channel.cpp | 10 +- modules/chanserv/main/chanserv.cpp | 20 +- modules/chanserv/mode.cpp | 12 +- modules/chanserv/register.cpp | 3 +- modules/chanserv/seen.cpp | 8 +- modules/chanserv/set.cpp | 85 ++++-- modules/chanserv/set_misc.cpp | 8 +- modules/chanserv/suspend.cpp | 11 +- modules/chanserv/sync.cpp | 2 +- modules/chanserv/topic.cpp | 11 +- modules/chanserv/unban.cpp | 10 +- modules/chanserv/updown.cpp | 11 +- modules/chanserv/xop.cpp | 46 +-- modules/database/flatfile.cpp | 2 +- modules/database/old.cpp | 20 +- modules/database/redis.cpp | 28 +- modules/database/sql.cpp | 2 +- modules/dns.cpp | 66 ++--- modules/dnsbl.cpp | 4 +- modules/encryption/bcrypt.cpp | 12 +- modules/encryption/md5.cpp | 2 +- modules/encryption/none.cpp | 2 +- modules/encryption/old.cpp | 3 +- modules/encryption/sha1.cpp | 2 +- modules/encryption/sha256.cpp | 2 +- modules/extra/ldap.cpp | 6 +- modules/extra/ldap_authentication.cpp | 4 +- modules/extra/mysql.cpp | 8 +- modules/extra/sql_authentication.cpp | 6 +- modules/extra/sql_log.cpp | 16 +- modules/extra/sql_oper.cpp | 6 +- modules/extra/ssl_gnutls.cpp | 4 +- modules/extra/ssl_openssl.cpp | 4 +- modules/extra/stats/chanstats.cpp | 12 +- modules/extra/stats/cs_fantasy_stats.cpp | 6 +- modules/extra/stats/cs_fantasy_top.cpp | 6 +- modules/fantasy.cpp | 6 +- modules/global/global.cpp | 3 +- modules/greet.cpp | 10 +- modules/hostserv/add.cpp | 2 +- modules/hostserv/del.cpp | 5 +- modules/hostserv/off.cpp | 2 +- modules/hostserv/on.cpp | 2 +- modules/hostserv/request.cpp | 8 +- modules/hostserv/set.cpp | 2 + modules/httpd.cpp | 26 +- modules/memoserv/send.cpp | 2 +- modules/memoserv/sendall.cpp | 2 +- modules/nickserv/access.cpp | 8 +- modules/nickserv/ajoin.cpp | 4 +- modules/nickserv/cert.cpp | 12 +- modules/nickserv/drop.cpp | 5 +- modules/nickserv/getemail.cpp | 2 +- modules/nickserv/group.cpp | 10 +- modules/nickserv/identify.cpp | 13 +- modules/nickserv/info.cpp | 10 +- modules/nickserv/list.cpp | 8 +- modules/nickserv/logout.cpp | 4 +- modules/nickserv/main/account.cpp | 2 +- modules/nickserv/main/nickserv.cpp | 11 +- modules/nickserv/maxemail.cpp | 2 +- modules/nickserv/recover.cpp | 8 +- modules/nickserv/register.cpp | 11 +- modules/nickserv/resetpass.cpp | 5 +- modules/nickserv/set.cpp | 67 +++-- modules/nickserv/suspend.cpp | 11 +- modules/operserv/akill.cpp | 20 +- modules/operserv/chankill.cpp | 2 +- modules/operserv/config.cpp | 5 +- modules/operserv/defcon.cpp | 26 +- modules/operserv/dns.cpp | 44 +-- modules/operserv/forbid.cpp | 8 +- modules/operserv/ignore.cpp | 16 +- modules/operserv/info.cpp | 9 +- modules/operserv/jupe.cpp | 4 +- modules/operserv/kick.cpp | 2 +- modules/operserv/kill.cpp | 4 +- modules/operserv/list.cpp | 8 +- modules/operserv/login.cpp | 6 +- modules/operserv/logsearch.cpp | 6 +- modules/operserv/main/operserv.cpp | 27 +- modules/operserv/mode.cpp | 17 +- modules/operserv/modinfo.cpp | 7 +- modules/operserv/module.cpp | 8 +- modules/operserv/news.cpp | 14 +- modules/operserv/noop.cpp | 7 +- modules/operserv/oper.cpp | 6 +- modules/operserv/reload.cpp | 4 +- modules/operserv/session.cpp | 14 +- modules/operserv/set.cpp | 23 +- modules/operserv/shutdown.cpp | 4 +- modules/operserv/stats.cpp | 4 +- modules/operserv/svs.cpp | 17 +- modules/operserv/sxline.cpp | 39 ++- modules/protocol/bahamut.cpp | 7 +- modules/protocol/hybrid.cpp | 6 +- modules/protocol/inspircd20.cpp | 34 ++- modules/protocol/ngircd.cpp | 17 +- modules/protocol/rfc1459.cpp | 17 +- modules/protocol/unreal.cpp | 9 +- modules/redis.cpp | 26 +- modules/rewrite.cpp | 6 +- modules/sasl.cpp | 9 +- modules/sqlite.cpp | 14 +- modules/webcpanel/static_fileserver.cpp | 2 +- modules/webcpanel/template_fileserver.cpp | 26 +- modules/xmlrpc.cpp | 2 +- src/bots.cpp | 6 +- src/channels.cpp | 67 ++--- src/command.cpp | 39 ++- src/config.cpp | 16 +- src/extensible.cpp | 2 +- src/init.cpp | 100 +++---- src/language.cpp | 17 +- src/logger.cpp | 445 +++++++++++++++++------------- src/mail.cpp | 4 +- src/main.cpp | 11 +- src/misc.cpp | 43 ++- src/modes.cpp | 12 +- src/module.cpp | 20 +- src/modulemanager.cpp | 42 +-- src/process.cpp | 22 +- src/serialize.cpp | 32 +-- src/servers.cpp | 16 +- src/service_manager.cpp | 8 +- src/socket_clients.cpp | 8 +- src/socketengines/socketengine_epoll.cpp | 2 +- src/socketengines/socketengine_kqueue.cpp | 2 +- src/socketengines/socketengine_poll.cpp | 2 +- src/socketengines/socketengine_select.cpp | 2 +- src/sockets.cpp | 2 +- src/uplink.cpp | 30 +- src/users.cpp | 36 +-- src/xline.cpp | 2 +- 169 files changed, 1689 insertions(+), 1161 deletions(-) diff --git a/include/anope.h b/include/anope.h index 02a8c3fef..07e275e2f 100644 --- a/include/anope.h +++ b/include/anope.h @@ -148,6 +148,7 @@ namespace Anope inline void push_back(char c) { return this->_string.push_back(c); } inline string& insert(const_iterator p, char c) { this->_string.insert(p, c); return *this; } + inline string& insert(size_t pos, const string& str) { this->_string.insert(pos, str._string); return *this; } inline string& append(const string &s) { this->_string.append(s.str()); return *this; } inline string& append(const char *s, size_t n) { this->_string.append(s, n); return *this; } @@ -550,6 +551,8 @@ namespace Anope * @param len The length of the string returned */ extern CoreExport Anope::string Random(size_t len); + + extern Logger Logger; } /** sepstream allows for splitting token separated lists. @@ -732,7 +735,8 @@ operator>>(std::istream &is, T& t) /** Convert something to a string */ -template inline Anope::string stringify(const T &x) +template +inline Anope::string stringify(const T &x) { std::ostringstream stream; @@ -742,6 +746,12 @@ template inline Anope::string stringify(const T &x) return stream.str(); } +template<> +inline Anope::string stringify(const Anope::string &str) +{ + return str; +} + template inline void convert(const Anope::string &s, T &x, Anope::string &leftover, bool failIfLeftoverChars = true) { leftover.clear(); @@ -819,39 +829,47 @@ inline kwarg operator"" _kw(const char *literal, size_t n) return { literal }; } -struct FormatInfo +class FormatInfo { Anope::string format; std::vector parameters; unsigned int pos = 0; + public: FormatInfo(const Anope::string &fmt, size_t size) : format(fmt), parameters(size) { } template - void Add(T& arg) + void Add(const T& arg) { - parameters[pos] = kwarg{ stringify(pos).c_str() } = stringify(arg); - ++pos; + kwarg k = kwarg{ stringify(pos), stringify(arg) }; + Add(k); } + void AddArgs() { } + template - void Format(Arg &&arg, Args&&... args) + void AddArgs(Arg &&arg, Args&&... args) { Add(arg); - Format(std::forward(args)...); + AddArgs(std::forward(args)...); } - void Format() - { - for (kwarg& arg : parameters) - format = format.replace_all_cs("{" + arg.name + "}", arg.value); - } + const kwarg *GetKwarg(const Anope::string &name) const; + + void Format(); + + const Anope::string &GetFormat() const; }; template<> -inline void FormatInfo::Add(kwarg &arg) +inline void FormatInfo::Add(const kwarg &arg) { - parameters[pos++] = arg; + unsigned int p = pos++; + + if (p >= parameters.size()) + parameters.resize(p + 1); + + parameters[p] = arg; } namespace Anope @@ -860,8 +878,9 @@ namespace Anope inline Anope::string Format(const Anope::string &format, Args&&... args) { FormatInfo fi(format, sizeof...(Args)); - fi.Format(std::forward(args)...); - return fi.format; + fi.AddArgs(std::forward(args)...); + fi.Format(); + return fi.GetFormat(); } } diff --git a/include/bots.h b/include/bots.h index 928107ef3..6432a15b3 100644 --- a/include/bots.h +++ b/include/bots.h @@ -37,7 +37,8 @@ class CoreExport ServiceBot : public LocalUser /* Modes the bot should have as configured in service:modes */ Anope::string botmodes; /* Whether or not this bot is introduced to the network */ - bool introduced; + bool introduced = false; + Logger logger; /** Create a new bot. * @param nick The nickname to assign to the bot. @@ -140,7 +141,7 @@ class BotInfo : public Serialize::Object public: static constexpr const char *const NAME = "botinfo"; - ServiceBot *bot; + ServiceBot *bot = nullptr; Configuration::Block *conf = nullptr; using Serialize::Object::Object; diff --git a/include/channels.h b/include/channels.h index 31fa582c4..49daf6f7e 100644 --- a/include/channels.h +++ b/include/channels.h @@ -58,9 +58,9 @@ class CoreExport Channel : public Base, public Extensible /* When the channel was created */ time_t creation_time; /* If the channel has just been created in a netjoin */ - bool syncing; + bool syncing = false; /* Is configured in the conf as a channel bots should be in */ - bool botchannel; + bool botchannel = false; /* Users in the channel */ typedef std::map ChanUserList; @@ -74,15 +74,17 @@ class CoreExport Channel : public Base, public Extensible * This is the time the topic was *originally set*. When we restore the topic we want to change the TS back * to this, but we can only do this on certain IRCds. */ - time_t topic_ts; + time_t topic_ts = 0; /* The actual time the topic was set, probably close to Anope::CurTime */ - time_t topic_time; + time_t topic_time = 0; - time_t server_modetime; /* Time of last server MODE */ - time_t chanserv_modetime; /* Time of last check_modes() */ - int16_t server_modecount; /* Number of server MODEs this second */ - int16_t chanserv_modecount; /* Number of check_mode()'s this sec */ - int16_t bouncy_modes; /* Did we fail to set modes here? */ + time_t server_modetime = 0; /* Time of last server MODE */ + time_t chanserv_modetime = 0; /* Time of last check_modes() */ + int16_t server_modecount = 0; /* Number of server MODEs this second */ + int16_t chanserv_modecount = 0; /* Number of check_mode()'s this sec */ + int16_t bouncy_modes = 0; /* Did we fail to set modes here? */ + + Logger logger; private: /** Constructor @@ -96,6 +98,11 @@ class CoreExport Channel : public Base, public Extensible */ ~Channel(); + /** Gets the channels name + * @return the channel name + */ + const Anope::string &GetName() const; + /** Call if we need to unset all modes and clear all user status (internally). * Only useful if we get a SJOIN with a TS older than what we have here */ diff --git a/include/commands.h b/include/commands.h index 8cdb0d544..5431df7a5 100644 --- a/include/commands.h +++ b/include/commands.h @@ -86,6 +86,9 @@ class CoreExport CommandSource const Anope::string &GetNick() const; User *GetUser(); NickServ::Account *GetAccount(); + Anope::string GetSource(); + const Anope::string &GetCommand() const; + ChanServ::AccessGroup AccessFor(ChanServ::Channel *ci); bool IsFounder(ChanServ::Channel *ci); @@ -111,11 +114,13 @@ class CoreExport Command : public Service Anope::string desc; std::vector syntax; /* Allow unregistered users to use this command */ - bool allow_unregistered; + bool allow_unregistered = false; /* Command requires that a user is executing it */ - bool require_user; + bool require_user = false; public: + static constexpr const char *NAME = "Command"; + /* Maximum paramaters accepted by this command */ size_t max_params; /* Minimum parameters required to use this command */ @@ -124,9 +129,8 @@ class CoreExport Command : public Service /* Module which owns us */ Module *module; - static constexpr const char *NAME = "Command"; + Logger logger; - protected: /** Create a new command. * @param owner The owner of the command * @param sname The command name @@ -136,10 +140,8 @@ class CoreExport Command : public Service */ Command(Module *owner, const Anope::string &sname, size_t min_params, size_t max_params = 0); - public: virtual ~Command(); - protected: void SetDesc(const Anope::string &d); void ClearSyntax(); @@ -148,7 +150,6 @@ class CoreExport Command : public Service void AllowUnregistered(bool b); void RequireUser(bool b); - public: void SendSyntax(CommandSource &); bool AllowUnregistered() const; bool RequireUser() const; diff --git a/include/defs.h b/include/defs.h index b25183062..989ce3e5b 100644 --- a/include/defs.h +++ b/include/defs.h @@ -42,6 +42,7 @@ class IRCDProto; class ListenSocket; class Log; class LogInfo; +class Logger; namespace NickServ { class Account; diff --git a/include/event.h b/include/event.h index fcc292aea..85e406795 100644 --- a/include/event.h +++ b/include/event.h @@ -1074,7 +1074,7 @@ namespace Event /** Called when a message is logged * @param l The log message */ - virtual void OnLog(::Log *l) anope_abstract; + virtual void OnLog(Logger *l) anope_abstract; }; struct CoreExport LogMessage : Events @@ -1089,7 +1089,7 @@ namespace Event * @param l The log message * @param msg The final formatted message, derived from 'l' */ - virtual void OnLogMessage(LogInfo *li, const ::Log *l, const Anope::string &msg) anope_abstract; + virtual void OnLogMessage(LogInfo *li, const Logger *l, const Anope::string &msg) anope_abstract; }; struct CoreExport CheckModes : Events diff --git a/include/extensible.h b/include/extensible.h index 2e1079631..cc18b5e5c 100644 --- a/include/extensible.h +++ b/include/extensible.h @@ -137,7 +137,7 @@ T* Extensible::GetExt(const Anope::string &name) if (ref) return ref->Get(this); - Log(LOG_DEBUG) << "GetExt for nonexistent type " << name << " on " << static_cast(this); + Anope::Logger.Debug("GetExt for nonexistent type {0} on {1}", name, static_cast(this)); return NULL; } @@ -151,7 +151,7 @@ T* Extensible::Extend(const Anope::string &name, const T &what) return ref->Get(this); } - Log(LOG_DEBUG) << "Extend for nonexistent type " << name << " on " << static_cast(this); + Anope::Logger.Debug("Extend for nonexistent type {0} on {1}", name, static_cast(this)); return NULL; } @@ -162,6 +162,6 @@ void Extensible::Shrink(const Anope::string &name) if (ref) ref->Unset(this); else - Log(LOG_DEBUG) << "Shrink for nonexistent type " << name << " on " << static_cast(this); + Anope::Logger.Debug("Shrink for nonexistent type {0} on {1}", name, static_cast(this)); } diff --git a/include/logger.h b/include/logger.h index f3b00068b..d368eb142 100644 --- a/include/logger.h +++ b/include/logger.h @@ -21,28 +21,33 @@ #include "anope.h" #include "defs.h" +#include "language.h" -enum LogType +enum class LogType { + NORMAL, /* Used whenever an administrator uses an administrative comand */ - LOG_ADMIN, + ADMIN, /* Used whenever an administrator overides something, such as adding * access to a channel where they don't have permission to. */ - LOG_OVERRIDE, + 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 + COMMAND, + SERVER, + CHANNEL, + USER, + MODULE +}; + +enum class LogLevel +{ + NORMAL, + TERMINAL, + RAWIO, + DEBUG, + DEBUG_2, + DEBUG_3 }; struct LogFile @@ -55,96 +60,170 @@ struct LogFile const Anope::string &GetName() const; }; -/* Represents a single log message */ -class CoreExport Log +/* Configured in the configuration file, actually does the message logging */ +class CoreExport LogInfo { public: - /* Bot that should log this message */ - ServiceBot *bi; - /* For commands, the user executing the command, but might not always exist */ - User *u; - /* For commands, the account executing the command, but will not always exist */ - NickServ::Account *nc; - /* For commands, the command being executed */ - Command *c; - /* For commands, the command source */ - CommandSource *source; - /* Used for LOG_CHANNEL */ - Channel *chan; - /* For commands, the channel the command was executed on, will not always exist */ - ChanServ::Channel *ci; - /* For LOG_SERVER */ - Server *s; - /* For LOG_MODULE */ - Module *m; - LogType type; - Anope::string category; + ServiceBot *bot = nullptr; + std::vector targets; + std::vector logfiles; + int last_day = 0; + std::vector sources; + int log_age = 0; + std::vector admin; + std::vector override; + std::vector commands; + std::vector servers; + std::vector users; + std::vector channels; + std::vector normal; + bool raw_io = false; + bool debug = false; - std::stringstream buf; + LogInfo(int logage, bool rawio, bool debug); - Log(LogType type = LOG_NORMAL, const Anope::string &category = "", ServiceBot *bi = NULL); + ~LogInfo(); + + void OpenLogFiles(); - /* LOG_COMMAND/OVERRIDE/ADMIN */ - Log(LogType type, CommandSource &source, Command *c, ChanServ::Channel *ci = NULL); + bool HasType(LogType ltype, LogLevel level, const Anope::string &type) const; - /* LOG_CHANNEL */ - Log(User *u, Channel *c, const Anope::string &category = ""); + void ProcessMessage(const Logger *l, const Anope::string &message); +}; - /* LOG_USER */ - Log(User *u, const Anope::string &category = "", ServiceBot *bi = NULL); +class Logger +{ + friend class LogInfo; - /* LOG_SERVER */ - Log(Server *s, const Anope::string &category = "", ServiceBot *bi = NULL); + LogType type = LogType::NORMAL; + LogLevel level = LogLevel::NORMAL; - Log(ServiceBot *b, const Anope::string &category = ""); + /* Object logger is attached to */ + Module *module = nullptr; + Command *command = nullptr; + ServiceBot *bot = nullptr; + Server *server = nullptr; - Log(Module *m, const Anope::string &category = "", ServiceBot *bi = NULL); + /* Logger category */ + Anope::string category; + /* Non formatted message */ + Anope::string raw_message; - ~Log(); + /* Sources */ + User *user = nullptr; + NickServ::Account *account = nullptr; + Channel *channel = nullptr; + ChanServ::Channel *ci = nullptr; + CommandSource *source = nullptr; - private: Anope::string FormatSource() const; - Anope::string FormatCommand() const; - - public: Anope::string BuildPrefix() const; + void LogMessage(const Anope::string &message); + void InsertVariables(FormatInfo &fi); - template Log &operator<<(T val) + template + Anope::string Format(const Anope::string &message, Args&&... args) { - this->buf << val; - return *this; + FormatInfo fi(message, sizeof...(Args)); + fi.AddArgs(std::forward(args)...); + InsertVariables(fi); + fi.Format(); + return fi.GetFormat(); } -}; -/* Configured in the configuration file, actually does the message logging */ -class CoreExport LogInfo -{ public: - ServiceBot *bot; - std::vector targets; - std::vector logfiles; - int last_day; - std::vector sources; - int log_age; - std::vector admin; - std::vector override; - std::vector commands; - std::vector servers; - std::vector users; - std::vector channels; - std::vector normal; - bool raw_io; - bool debug; + Logger() = default; + Logger(Module *m) : type(LogType::MODULE), module(m) { } + Logger(Command *c) : type(LogType::COMMAND), command(c) { } + Logger(ServiceBot *b) : bot(b) { } + Logger(Channel *c) : type(LogType::CHANNEL), channel(c) { } + Logger(User *u) : type(LogType::USER), user(u) { } + Logger(Server *s) : type(LogType::SERVER), server(s) { } + + LogType GetType() const; + LogLevel GetLevel() const; + + Module *GetModule() const; + Command *GetCommand() const; + ServiceBot *GetBot() const; + Server *GetServer() const; + + User *GetUser() const; + void SetUser(User *); + + NickServ::Account *GetAccount() const; + void SetAccount(NickServ::Account *); + + Channel *GetChannel() const; + void SetChannel(Channel *); + + ChanServ::Channel *GetCi() const; + void SetCi(ChanServ::Channel *); + + CommandSource *GetSource() const; + void SetSource(CommandSource *); + + Logger Category(const Anope::string &c) const; + Logger User(class User *u) const; + Logger Channel(class Channel *c) const; + Logger Channel(ChanServ::Channel *c) const; + Logger Source(CommandSource *s) const; + Logger Bot(ServiceBot *bot) const; + Logger Bot(const Anope::string &name) const; + + template void Log(LogLevel level, const Anope::string &message, Args&&... args) + { + Logger l = *this; + l.raw_message = message; + l.level = level; - LogInfo(int logage, bool rawio, bool debug); + Anope::string translated = Language::Translate(message); + l.LogMessage(l.Format(translated, std::forward(args)...)); + } - ~LogInfo(); + template void Command(LogType type, CommandSource &source, ChanServ::Channel *ci, const Anope::string &message, Args&&... args) + { + Logger l = *this; + l.SetSource(&source); + l.SetCi(ci); - void OpenLogFiles(); + Anope::string translated = Language::Translate(message); + l.LogMessage(l.Format(translated, std::forward(args)...)); + } + + template void Command(LogType type, CommandSource &source, const Anope::string &message, Args&&... args) + { + Command(type, source, nullptr, message, std::forward(args)...); + } - bool HasType(LogType ltype, const Anope::string &type) const; + template void Log(const Anope::string &message, Args&&... args) + { + Log(LogLevel::NORMAL, message, std::forward(args)...); + } + + template void Terminal(const Anope::string &message, Args&&... args) + { + Log(LogLevel::TERMINAL, message, std::forward(args)...); + } + + template void RawIO(const Anope::string &message, Args&&... args) + { + Log(LogLevel::RAWIO, message, std::forward(args)...); + } - /* Logs the message l if configured to */ - void ProcessMessage(const Log *l); + template void Debug(const Anope::string &message, Args&&... args) + { + Log(LogLevel::DEBUG, message, std::forward(args)...); + } + + template void Debug2(const Anope::string &message, Args&&... args) + { + Log(LogLevel::DEBUG_2, message, std::forward(args)...); + } + + template void Debug3(const Anope::string &message, Args&&... args) + { + Log(LogLevel::DEBUG_3, message, std::forward(args)...); + } }; diff --git a/include/modules.h b/include/modules.h index ff9303c4f..eb3b15094 100644 --- a/include/modules.h +++ b/include/modules.h @@ -212,6 +212,8 @@ class CoreExport Module : public Extensible */ Anope::string author; + Logger logger; + /** Creates and initialises a new module. * @param modname The module name * @param loadernick The nickname of the user loading the module. @@ -223,6 +225,8 @@ class CoreExport Module : public Extensible */ virtual ~Module(); + const Anope::string &GetName() const; + /** Toggles the permanent flag on a module. If a module is permanent, * then it may not be unloaded. * diff --git a/include/modules/dns.h b/include/modules/dns.h index e98826ce7..5eb0f3950 100644 --- a/include/modules/dns.h +++ b/include/modules/dns.h @@ -176,7 +176,7 @@ namespace DNS */ void Tick(time_t) override { - Log(LOG_DEBUG_2) << "Resolver: timeout for query " << this->name; + Anope::Logger.Debug2("Resolver: timeout for query {0}", this->name); Query rr(*this); rr.error = ERROR_TIMEDOUT; this->OnError(&rr); diff --git a/include/modules/redis.h b/include/modules/redis.h index dc8c1e75f..c26ad194f 100644 --- a/include/modules/redis.h +++ b/include/modules/redis.h @@ -54,14 +54,16 @@ namespace Redis class Interface { - public: Module *owner; + public: Interface(Module *m) : owner(m) { } virtual ~Interface() = default; + Module *GetOwner() const { return owner; } + virtual void OnResult(const Reply &r) anope_abstract; - virtual void OnError(const Anope::string &error) { Log(owner) << error; } + virtual void OnError(const Anope::string &error) { owner->logger.Log(error); } }; class FInterface : public Interface diff --git a/include/protocol.h b/include/protocol.h index 4dc115fe6..89d337594 100644 --- a/include/protocol.h +++ b/include/protocol.h @@ -112,7 +112,8 @@ public: if (!sender) { - Log(LOG_DEBUG) << "No message sender for type " << T::NAME; + const char *const name = T::NAME; + Anope::Logger.Debug("No message sender for type {0}", name); return; } diff --git a/include/serialize.h b/include/serialize.h index 67be96c0c..90aedc7ae 100644 --- a/include/serialize.h +++ b/include/serialize.h @@ -298,7 +298,7 @@ class Serialize::Type : public Base if (s->GetSerializableType() != this) { - Log(LOG_DEBUG) << "Mismatch for required id " << id << ", is of type " << s->GetSerializableType()->GetName() << " but wants " << this->GetName(); + Anope::Logger.Debug("Mismatch for required id {0}, is of type {1} but wants {2}", id, s->GetSerializableType()->GetName(), this->GetName()); return nullptr; } @@ -649,7 +649,6 @@ class Serialize::Field : public CommonFieldBase } catch (const ConvertException &) { - Log(LOG_DEBUG) << "Unable to stringify " << t; return ""; } } @@ -737,7 +736,7 @@ class Serialize::ObjectField : public CommonFieldBase Serialize::TypeBase *base = Serialize::TypeBase::Find(type); if (base == nullptr) { - Log(LOG_DEBUG_2) << "OnSerializeGetSerializable returned unknown type " << type; + Anope::Logger.Debug2("OnSerializeGetSerializable returned unknown type {0}", type); return nullptr; } @@ -894,7 +893,7 @@ T Serialize::New() if (type == nullptr) { - Log(LOG_DEBUG) << "Serialize::New with unknown type " << name; + Anope::Logger.Debug("Serialize::New with unknown type {0}", name); return nullptr; } @@ -908,7 +907,7 @@ inline std::vector Serialize::Object::GetRefs(Serialize::Ty if (types.empty()) { - Log(LOG_DEBUG) << "GetRefs for unknown type on #" << this->id << " type " << s_type->GetName() << " named " << type->GetName(); + Anope::Logger.Debug("GetRefs for unknown type on #{0} type {1} named {2}", this->id, s_type->GetName(), type->GetName()); return objs; } @@ -929,7 +928,7 @@ std::vector Serialize::Object::GetRefs() if (types.empty()) { - Log(LOG_DEBUG) << "GetRefs for unknown type on #" << this->id << " type " << s_type->GetName() << " named " << name; + Anope::Logger.Debug("GetRefs for unknown type on #{0} type {1} named {2}", this->id, s_type->GetName(), name); return objs; } @@ -947,7 +946,7 @@ void Serialize::Object::SetS(const Anope::string &name, const T &what) FieldBase *field = s_type->GetField(name); if (field == nullptr) { - Log(LOG_DEBUG) << "Set for unknown field " << name << " on " << s_type->GetName(); + Anope::Logger.Debug("Set for unknown field {0} on {1}", name, s_type->GetName()); return; } @@ -961,7 +960,7 @@ void Serialize::Object::UnsetS(const Anope::string &name) FieldBase *field = s_type->GetField(name); if (field == nullptr) { - Log(LOG_DEBUG) << "Unset for unknown field " << name << " on " << s_type->GetName(); + Anope::Logger.Debug("Unset for unknown field {0} on {1}", name, s_type->GetName()); return; } @@ -974,7 +973,7 @@ inline bool Serialize::Object::HasFieldS(const Anope::string &name) FieldBase *field = s_type->GetField(name); if (field == nullptr) { - Log(LOG_DEBUG) << "HasField for unknown field " << name << " on " << s_type->GetName(); + Anope::Logger.Debug("HasField for unknown field {0} on {1}", name, s_type->GetName()); return false; } diff --git a/include/servers.h b/include/servers.h index 64a265a85..27273f7aa 100644 --- a/include/servers.h +++ b/include/servers.h @@ -78,7 +78,7 @@ class CoreExport Server : public Extensible * @param sid Server sid/numeric * @param jupe If the server is juped */ - Server(Server *uplink, const Anope::string &name, unsigned hops, const Anope::string &description, const Anope::string &sid = "", bool jupe = false); + Server(Server *uplink, const Anope::string &name, unsigned int hops, const Anope::string &description, const Anope::string &sid = "", bool jupe = false); private: /** Destructor @@ -87,7 +87,9 @@ class CoreExport Server : public Extensible public: /* Number of users on the server */ - unsigned users; + unsigned int users; + + Logger logger; void Burst(); diff --git a/include/users.h b/include/users.h index be4ee2a39..de9cc5b42 100644 --- a/include/users.h +++ b/include/users.h @@ -71,6 +71,8 @@ class CoreExport User : public virtual Base, public virtual Extensible, public C public: UserType type = UserType::USER; + Logger logger; + /* User's current nick */ Anope::string nick; @@ -367,12 +369,11 @@ class CoreExport User : public virtual Base, public virtual Extensible, public C /* Returns a mask that will most likely match any address the * user will have from that location. For IP addresses, wildcards the - * appropriate subnet mask (e.g. 35.1.1.1 -> 35.*; 128.2.1.1 -> 128.2.*); - * for named addresses, wildcards the leftmost part of the name unless the - * name only contains two parts. If the username begins with a ~, delete - * it. + * last octet (e.g. 35.1.1.1 -> 35.1.1.*). for named addresses, wildcards + * the leftmost part of the name unless the name only contains two parts. + * If the username begins with a ~, replace with *. */ - Anope::string Mask() const; + Anope::string WildMask() const; /** Notes the usage of an incorrect password. If too many * incorrect passwords are used the user might be killed. diff --git a/modules/botserv/assign.cpp b/modules/botserv/assign.cpp index eca103e9f..db368c75e 100644 --- a/modules/botserv/assign.cpp +++ b/modules/botserv/assign.cpp @@ -80,7 +80,7 @@ class CommandBSAssign : public Command } bool override = !access.HasPriv("ASSIGN"); - Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "for " << bi->nick; + logger.Command(override ? LogType::OVERRIDE : LogType::COMMAND, source, ci, _("{source} used {command} on {channel} to assign {0}"), bi->nick); bi->Assign(source.GetUser(), ci); source.Reply(_("Bot \002{0}\002 has been assigned to \002{1}\002."), bi->nick, ci->GetName()); @@ -147,7 +147,7 @@ class CommandBSUnassign : public Command } bool override = !access.HasPriv("ASSIGN"); - Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "for " << ci->GetBot()->nick; + logger.Command(override ? LogType::OVERRIDE : LogType::COMMAND, source, ci, _("{source} used {command} on {channel} to unassign {0}"), ci->GetBot()->nick); ServiceBot *bi = ci->GetBot(); bi->UnAssign(source.GetUser(), ci); @@ -192,7 +192,7 @@ class CommandBSSetNoBot : public Command if (value.equals_ci("ON")) { - Log(LOG_ADMIN, source, this, ci) << "to enable nobot"; + logger.Command(LogType::ADMIN, source, ci, _("{source} used {command} on {channel} to enable nobot")); ci->SetS("BS_NOBOT", true); if (ci->GetBot()) @@ -201,7 +201,7 @@ class CommandBSSetNoBot : public Command } else if (value.equals_ci("OFF")) { - Log(LOG_ADMIN, source, this, ci) << "to disable nobot"; + logger.Command(LogType::ADMIN, source, ci, _("{source} used {command} on {channel} to disable nobot")); ci->UnsetS("BS_NOBOT"); source.Reply(_("No-bot mode is now \002off\002 for \002{0}\002."), ci->GetName()); diff --git a/modules/botserv/autoassign.cpp b/modules/botserv/autoassign.cpp index 3bb6dce64..861d97f6f 100644 --- a/modules/botserv/autoassign.cpp +++ b/modules/botserv/autoassign.cpp @@ -37,7 +37,7 @@ class BSAutoAssign : public Module ServiceBot *bi = ServiceBot::Find(bot, true); if (bi == NULL) { - Log(this) << "bs_autoassign is configured to assign bot " << bot << ", but it does not exist?"; + logger.Log("bs_autoassign is configured to assign bot {0}, but it does not exist?", bot); return; } diff --git a/modules/botserv/badwords.cpp b/modules/botserv/badwords.cpp index 754e202a7..071414ac4 100644 --- a/modules/botserv/badwords.cpp +++ b/modules/botserv/badwords.cpp @@ -144,9 +144,9 @@ class CommandBSBadwords : public Command void DoList(CommandSource &source, ChanServ::Channel *ci, const Anope::string &word) { bool override = !source.AccessFor(ci).HasPriv("BADWORDS"); - Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "LIST"; - ListFormatter list(source.GetAccount()); + logger.Command(override ? LogType::OVERRIDE : LogType::COMMAND, source, ci, _("{source} used {command} on {channel} to list badwords")); + ListFormatter list(source.GetAccount()); list.AddColumn(_("Number")).AddColumn(_("Word")).AddColumn(_("Type")); if (!badwords->GetBadWordCount(ci)) @@ -244,7 +244,7 @@ class CommandBSBadwords : public Command } bool override = !source.AccessFor(ci).HasPriv("BADWORDS"); - Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "ADD " << realword; + logger.Command(override ? LogType::OVERRIDE : LogType::COMMAND, source, ci, _("{source} used {command} on {channel} to add {0}"), realword); badwords->AddBadWord(ci, realword, bwtype); source.Reply(_("\002{0}\002 added to \002{1}\002 bad words list."), realword, ci->GetName()); @@ -271,7 +271,8 @@ class CommandBSBadwords : public Command if (!num || num > badwords->GetBadWordCount(ci)) return; - Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "DEL " << badwords->GetBadWord(ci, num - 1)->GetWord(); + logger.Command(override ? LogType::OVERRIDE : LogType::COMMAND, source, ci, _("{source} used {command} on {channel} to remove {0}"), badwords->GetBadWord(ci, num - 1)->GetWord()); + ++deleted; badwords->EraseBadWord(ci, num - 1); }, @@ -304,7 +305,7 @@ class CommandBSBadwords : public Command return; } - Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "DEL " << bw->GetWord(); + logger.Command(override ? LogType::OVERRIDE : LogType::COMMAND, source, ci, _("{source} used {command} on {channel} to remove {3}"), bw->GetWord()); source.Reply(_("\002{0}\002 deleted from \002{1}\002 bad words list."), bw->GetWord(), ci->GetName()); @@ -315,7 +316,7 @@ class CommandBSBadwords : public Command void DoClear(CommandSource &source, ChanServ::Channel *ci) { bool override = !source.AccessFor(ci).HasPriv("BADWORDS"); - Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "CLEAR"; + logger.Command(override ? LogType::OVERRIDE : LogType::COMMAND, source, ci, _("{source} used {command} on {channel} to clear the badwords list")); badwords->ClearBadWords(ci); source.Reply(_("Bad words list is now empty.")); diff --git a/modules/botserv/bot.cpp b/modules/botserv/bot.cpp index 082bd6337..4eb5d2069 100644 --- a/modules/botserv/bot.cpp +++ b/modules/botserv/bot.cpp @@ -103,7 +103,7 @@ class CommandBSBot : public Command bi->bi = botinfo; botinfo->bot = bi; - Log(LOG_ADMIN, source, this) << "ADD " << bi->GetMask() << " " << bi->realname; + logger.Command(LogType::ADMIN, source, _("{source} used {command} to add bot {0} {1}"), bi->GetMask(), bi->realname); source.Reply(_("\002{0}!{1}@{2}\002 (\002{3}\002) added to the bot list."), bi->nick, bi->GetIdent(), bi->host, bi->realname); @@ -266,8 +266,10 @@ class CommandBSBot : public Command if (!user.empty()) bi->OnKill(); + logger.Command(LogType::ADMIN, source, _("{source} used {command} to change bot {0} to {1} {2}"), + oldnick, bi->GetMask(), bi->realname); + source.Reply(_("Bot \002{0}\002 has been changed to \002{1}!{2}@{3}\002 (\002{4}\002)."), oldnick, bi->nick, bi->GetIdent(), bi->host, bi->realname); - Log(LOG_ADMIN, source, this) << "CHANGE " << oldnick << " to " << bi->GetMask() << " " << bi->realname; EventManager::Get()->Dispatch(&Event::BotChange::OnBotChange, bi); } @@ -297,7 +299,7 @@ class CommandBSBot : public Command EventManager::Get()->Dispatch(&Event::BotDelete::OnBotDelete, bi); - Log(LOG_ADMIN, source, this) << "DEL " << bi->nick; + logger.Command(LogType::ADMIN, source, _("{source} used {command} to delete bot {0}"), bi->nick); source.Reply(_("Bot \002{0}\002 has been deleted."), bi->nick); delete bi; diff --git a/modules/botserv/control.cpp b/modules/botserv/control.cpp index 448a28baf..1785e65e9 100644 --- a/modules/botserv/control.cpp +++ b/modules/botserv/control.cpp @@ -75,7 +75,7 @@ class CommandBSSay : public Command ci->GetBot()->lastmsg = Anope::CurTime; bool override = !source.AccessFor(ci).HasPriv("SAY"); - Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "to say: " << text; + logger.Command(override ? LogType::OVERRIDE : LogType::COMMAND, source, ci, _("{source} used {command} on {channel} to say: {0}"), text); } bool OnHelp(CommandSource &source, const Anope::string &subcommand) override @@ -145,7 +145,7 @@ class CommandBSAct : public Command ci->GetBot()->lastmsg = Anope::CurTime; bool override = !source.AccessFor(ci).HasPriv("SAY"); - Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "to say: " << message; + logger.Command(override ? LogType::OVERRIDE : LogType::COMMAND, source, ci, _("{source} used {command} to say: {0}"), message); } bool OnHelp(CommandSource &source, const Anope::string &subcommand) override diff --git a/modules/botserv/kick.cpp b/modules/botserv/kick.cpp index a32656f62..745525fa3 100644 --- a/modules/botserv/kick.cpp +++ b/modules/botserv/kick.cpp @@ -637,12 +637,12 @@ class CommandBSKickBase : public Command source.Reply(_("Bot will now kick for \002{0}\002."), optname); bool override = !source.AccessFor(ci).HasPriv("SET"); - Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "to enable the " << optname << " kicker"; + logger.Command(override ? LogType::OVERRIDE : LogType::COMMAND, source, ci, _("{source} used {command} on {channel} to enable the {0} kicker"), optname); } else if (param.equals_ci("OFF")) { bool override = !source.AccessFor(ci).HasPriv("SET"); - Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "to disable the " << optname << " kicker"; + logger.Command(override ? LogType::OVERRIDE : LogType::COMMAND, source, ci, _("{source} used {command} on {channel} to disable the {0} kicker"), optname); (kd->*setter)(false); (kd->*ttbsetter)(0); @@ -1099,7 +1099,7 @@ class CommandBSSetDontKickOps : public Command if (params[1].equals_ci("ON")) { bool override = !access.HasPriv("SET"); - Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "to enable dontkickops"; + logger.Command(override ? LogType::OVERRIDE : LogType::COMMAND, source, ci, _("{source} used {command} on {channel} to enable dontkickops")); kd->SetDontKickOps(true); source.Reply(_("Bot \002won't kick ops\002 on channel \002{0}\002."), ci->GetName()); @@ -1107,7 +1107,7 @@ class CommandBSSetDontKickOps : public Command else if (params[1].equals_ci("OFF")) { bool override = !access.HasPriv("SET"); - Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "to disable dontkickops"; + logger.Command(override ? LogType::OVERRIDE : LogType::COMMAND, source, ci, _("{source} used {command} on {channel} to disable dontkickops")); kd->SetDontKickOps(false); source.Reply(_("Bot \002will kick ops\002 on channel \002{0}\002."), ci->GetName()); @@ -1165,7 +1165,7 @@ class CommandBSSetDontKickVoices : public Command if (params[1].equals_ci("ON")) { bool override = !access.HasPriv("SET"); - Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "to enable dontkickvoices"; + logger.Command(override ? LogType::OVERRIDE : LogType::COMMAND, source, ci, _("{source} used {command} on {channel} to enable dontkickvoices")); kd->SetDontKickVoices(true); source.Reply(_("Bot \002won't kick voices\002 on channel %s."), ci->GetName().c_str()); @@ -1173,7 +1173,7 @@ class CommandBSSetDontKickVoices : public Command else if (params[1].equals_ci("OFF")) { bool override = !access.HasPriv("SET"); - Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "to disable dontkickvoices"; + logger.Command(override ? LogType::OVERRIDE : LogType::COMMAND, source, ci, _("{source} used {command} on {channel} to disable dontkickvoices")); kd->SetDontKickVoices(false); source.Reply(_("Bot \002will kick voices\002 on channel %s."), ci->GetName().c_str()); @@ -1200,15 +1200,8 @@ struct BanData struct Data { Anope::string mask; - time_t last_use; - int16_t ttb[TTB_SIZE]; - - Data() - { - last_use = 0; - for (int i = 0; i < TTB_SIZE; ++i) - this->ttb[i] = 0; - } + time_t last_use = 0; + int16_t ttb[TTB_SIZE] = { 0 }; }; private: @@ -1269,7 +1262,7 @@ class BanDataPurger : public Timer void Tick(time_t) override { - Log(LOG_DEBUG) << "bs_main: Running bandata purger"; + this->GetOwner()->logger.Debug("Running bandata purger"); for (channel_map::iterator it = ChannelList.begin(), it_end = ChannelList.end(); it != it_end; ++it) { diff --git a/modules/botserv/set.cpp b/modules/botserv/set.cpp index 6ab429d97..6845281cb 100644 --- a/modules/botserv/set.cpp +++ b/modules/botserv/set.cpp @@ -140,7 +140,7 @@ class CommandBSSetBanExpire : public Command ci->SetBanExpire(t); bool override = !access.HasPriv("SET"); - Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "to change banexpire to " << arg; + logger.Command(override ? LogType::OVERRIDE : LogType::COMMAND, source, ci, _("{source} used {command} on {channel} to change banexpire to {0}"), arg); if (!t) source.Reply(_("Bot bans will no longer automatically expire.")); diff --git a/modules/chanserv/access.cpp b/modules/chanserv/access.cpp index 967df9025..6ad67733e 100644 --- a/modules/chanserv/access.cpp +++ b/modules/chanserv/access.cpp @@ -213,7 +213,8 @@ class CommandCSAccess : public Command EventManager::Get()->Dispatch(&Event::AccessAdd::OnAccessAdd, ci, source, access); - Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "to add " << mask << " with level " << level; + logger.Command(override ? LogType::OVERRIDE : LogType::COMMAND, source, ci, _("{source} used {command} on {channel} to add {0} with level {1}"), mask, level); + if (p != NULL) source.Reply(_("\002{0}\002 added to the access list of \002{1}\002 with privilege \002{2}\002 (level \002{3}\002)."), access->Mask(), ci->GetName(), p->name, level); else @@ -283,7 +284,7 @@ class CommandCSAccess : public Command source.Reply(_("There are no entries matching \002{0}\002 on the access list of \002{1}\002."), mask, ci->GetName()); else { - Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "to delete " << nicks; + logger.Command(override ? LogType::OVERRIDE : LogType::COMMAND, source, ci, _("{source} used {command} on {channel} to delete {0}"), mask); if (deleted == 1) source.Reply(_("Deleted \0021\002 entry from the access list of \002{0}\002."), ci->GetName()); @@ -308,7 +309,7 @@ class CommandCSAccess : public Command { source.Reply(_("\002{0}\002 deleted from the access list of \002{1}\002."), access->Mask(), ci->GetName()); bool override = !u_access.founder && !u_access.HasPriv("ACCESS_CHANGE") && !access->Mask().equals_ci(source.nc->GetDisplay()); - Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "to delete " << access->Mask(); + logger.Command(override ? LogType::OVERRIDE : LogType::COMMAND, source, ci, _("{source} used {command} on {channel} to delete {3}"), access->Mask()); EventManager::Get()->Dispatch(&Event::AccessDel::OnAccessDel, ci, source, access); delete access; @@ -458,7 +459,7 @@ class CommandCSAccess : public Command source.Reply(_("The access list of \002{0}\002 has been cleared."), ci->GetName()); bool override = !source.IsFounder(ci); - Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "to clear the access list"; + logger.Command(override ? LogType::OVERRIDE : LogType::COMMAND, source, ci, _("{source} used {command} on {channel} to clear the access list")); } public: @@ -672,7 +673,7 @@ class CommandCSLevels : public Command else { bool override = !source.AccessFor(ci).HasPriv("FOUNDER"); - Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "to set " << p->name << " to level " << level; + logger.Command(override ? LogType::OVERRIDE : LogType::COMMAND, source, ci, _("{source} used {command} on {channel} to set {0} to level {1}"), p->name, level); ci->SetLevel(p->name, level); EventManager::Get()->Dispatch(&Event::LevelChange::OnLevelChange, source, ci, p->name, level); @@ -699,7 +700,7 @@ class CommandCSLevels : public Command if (p != NULL) { bool override = !source.AccessFor(ci).HasPriv("FOUNDER"); - Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "to disable " << p->name; + logger.Command(override ? LogType::OVERRIDE : LogType::COMMAND, source, ci, _("{source} used {command} on {channel} to disable {0}"), p->name); ci->SetLevel(p->name, ChanServ::ACCESS_INVALID); EventManager::Get()->Dispatch(&Event::LevelChange::OnLevelChange, source, ci, p->name, ChanServ::ACCESS_INVALID); @@ -754,7 +755,7 @@ class CommandCSLevels : public Command void DoReset(CommandSource &source, ChanServ::Channel *ci) { bool override = !source.AccessFor(ci).HasPriv("FOUNDER"); - Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "to reset all levels"; + logger.Command(override ? LogType::OVERRIDE : LogType::COMMAND, source, ci, _("{source} used {command} on {channel} to reset all levels")); ci->ClearLevels(); EventManager::Get()->Dispatch(&Event::LevelChange::OnLevelChange, source, ci, "ALL", 0); diff --git a/modules/chanserv/akick.cpp b/modules/chanserv/akick.cpp index 9338a4dd7..35bca6818 100644 --- a/modules/chanserv/akick.cpp +++ b/modules/chanserv/akick.cpp @@ -302,7 +302,10 @@ class CommandCSAKick : public Command else ak = ci->AddAkick(source.GetNick(), mask, reason); - Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "to add " << mask << (reason == "" ? "" : ": ") << reason; + if (reason.empty()) + logger.Command(override ? LogType::OVERRIDE : LogType::COMMAND, source, ci, _("{source} used {command} on {channel} to add {0}"), mask); + else + logger.Command(override ? LogType::OVERRIDE : LogType::COMMAND, source, ci, _("{source} used {command} on {channel} to add {0} ({1})"), mask, reason); EventManager::Get()->Dispatch(&Event::Akick::OnAkickAdd, source, ci, ak); @@ -337,10 +340,11 @@ class CommandCSAKick : public Command EventManager::Get()->Dispatch(&Event::Akick::OnAkickDel, source, ci, ak); - Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "to delete " << (ak->GetAccount() ? ak->GetAccount()->GetDisplay() : ak->GetMask()); + logger.Command(override ? LogType::OVERRIDE : LogType::COMMAND, source, ci, _("{source} used {command} on {channel} to delete {0}"), + ak->GetAccount() ? ak->GetAccount()->GetDisplay() : ak->GetMask()); ++deleted; - delete ak; + ak->Delete(); }, [&]() { @@ -357,29 +361,33 @@ class CommandCSAKick : public Command { NickServ::Nick *na = NickServ::FindNick(mask); NickServ::Account *nc = na ? na->GetAccount() : nullptr; + AutoKick *match = nullptr; - unsigned int i, end; - for (i = 0, end = ci->GetAkickCount(); i < end; ++i) + for (unsigned int i = 0; i < ci->GetAkickCount(); ++i) { AutoKick *ak = ci->GetAkick(i); if (ak->GetAccount() ? ak->GetAccount() == nc : mask.equals_ci(ak->GetMask())) + { + match = ak; break; + } } - if (i == ci->GetAkickCount()) + if (match == nullptr) { source.Reply(_("\002{0}\002 was not found on the auto kick list of \002{1}\002."), mask, ci->GetName()); return; } - Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "to delete " << mask; + logger.Command(override ? LogType::OVERRIDE : LogType::COMMAND, source, ci, _("{source} used {command} on {channel} to delete {0}"), + match->GetAccount() ? match->GetAccount()->GetDisplay() : match->GetMask()); - EventManager::Get()->Dispatch(&Event::Akick::OnAkickDel, source, ci, ci->GetAkick(i)); + EventManager::Get()->Dispatch(&Event::Akick::OnAkickDel, source, ci, match); - delete ci->GetAkick(i); + source.Reply(_("\002{0}\002 deleted from the auto kick list of \002{1}\002."), match->GetAccount() ? match->GetAccount()->GetDisplay() : match->GetMask(), ci->GetName()); - source.Reply(_("\002{0}\002 deleted from the auto kick list of \002{1}\002."), mask, ci->GetName()); + match->Delete(); } } @@ -523,7 +531,8 @@ class CommandCSAKick : public Command } bool override = !source.AccessFor(ci).HasPriv("AKICK"); - Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "ENFORCE, affects " << count << " users"; + logger.Command(override ? LogType::OVERRIDE : LogType::COMMAND, source, ci, + _("{source} used {command} on {channel} to enforce the akick list, affects {0} users"), count); source.Reply(_("Autokick enforce for \002{0}\002 complete; \002{1}\002 users were affected."), ci->GetName(), count); } @@ -531,7 +540,7 @@ class CommandCSAKick : public Command void DoClear(CommandSource &source, ChanServ::Channel *ci) { bool override = !source.AccessFor(ci).HasPriv("AKICK"); - Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "to clear the akick list"; + logger.Command(override ? LogType::OVERRIDE : LogType::COMMAND, source, ci, _("{source} used {command} on {channel} to clear the akick list")); ci->ClearAkick(); source.Reply(_("The autokick list of \002{0}\002 has been cleared."), ci->GetName()); @@ -712,7 +721,8 @@ class CSAKick : public Module if (kick) { - Log(LOG_DEBUG_2) << u->nick << " matched akick " << (ak->GetAccount() ? ak->GetAccount()->GetDisplay() : ak->GetMask()); + logger.Debug2("{0} matched akick {1}", u->nick, ak->GetAccount() ? ak->GetAccount()->GetDisplay() : ak->GetMask()); + ak->SetLastUsed(Anope::CurTime); if (!ak->GetAccount() && ak->GetMask().find('#') == Anope::string::npos) mask = ak->GetMask(); diff --git a/modules/chanserv/ban.cpp b/modules/chanserv/ban.cpp index 2b73df8fb..d79afe071 100644 --- a/modules/chanserv/ban.cpp +++ b/modules/chanserv/ban.cpp @@ -152,7 +152,7 @@ class CommandCSBan : public Command Anope::string mask = ci->GetIdealBan(u2); bool override = !u_access.HasPriv("BAN") || (u != u2 && ci->IsPeace() && u2_access >= u_access); - Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "for " << mask; + logger.Command(override ? LogType::OVERRIDE : LogType::COMMAND, source, ci, _("{source} used {command} on {channel} for {0}"), mask); if (!c->HasMode(mode, mask)) { @@ -188,7 +188,7 @@ class CommandCSBan : public Command Anope::string mask = IRCD->NormalizeMask(target); - Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "for " << mask; + logger.Command(override ? LogType::OVERRIDE : LogType::COMMAND, source, ci, _("{source} used {command} on {channel} for {0}"), mask); if (!c->HasMode(mode, mask)) { diff --git a/modules/chanserv/clone.cpp b/modules/chanserv/clone.cpp index 8d0c1ce3a..343e6c5b2 100644 --- a/modules/chanserv/clone.cpp +++ b/modules/chanserv/clone.cpp @@ -209,7 +209,8 @@ public: return; } - Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "to clone " << (what.empty() ? "everything from it" : what) << " to " << target_ci->GetName(); + logger.Command(override ? LogType::OVERRIDE : LogType::COMMAND, source, ci, _("{source} used {command} on {channel} to clone {0} to {1}"), + what.empty() ? "everything from it" : what, target_ci->GetName()); } bool OnHelp(CommandSource &source, const Anope::string &subcommand) override diff --git a/modules/chanserv/drop.cpp b/modules/chanserv/drop.cpp index 77ab7e55e..122ac96b8 100644 --- a/modules/chanserv/drop.cpp +++ b/modules/chanserv/drop.cpp @@ -63,7 +63,8 @@ class CommandCSDrop : public Command return; bool override = (ci->IsSecureFounder() ? !source.IsFounder(ci) : !source.AccessFor(ci).HasPriv("FOUNDER")); - Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "(founder was: " << (ci->GetFounder() ? ci->GetFounder()->GetDisplay() : "none") << ")"; + logger.Command(override ? LogType::OVERRIDE : LogType::COMMAND, source, ci, _("{source} used {command} on {channel} (founder was: {0})"), + ci->GetFounder() ? ci->GetFounder()->GetDisplay() : "none"); Reference c = ci->c; ci->Delete(); diff --git a/modules/chanserv/enforce.cpp b/modules/chanserv/enforce.cpp index e1d084075..8d41c7af3 100644 --- a/modules/chanserv/enforce.cpp +++ b/modules/chanserv/enforce.cpp @@ -25,7 +25,7 @@ class CommandCSEnforce : public Command void DoSecureOps(CommandSource &source, ChanServ::Channel *ci) { bool override = !source.AccessFor(ci).HasPriv("AKICK") && source.HasPriv("chanserv/access/modify"); - Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "to enforce secureops"; + logger.Command(override ? LogType::OVERRIDE : LogType::COMMAND, source, ci, _("{source} used {command} on {channel} to enforce secureops")); /* Dirty hack to allow Channel::SetCorrectModes to work ok. * We pretend like SECUREOPS is on so it doesn't ignore that @@ -51,7 +51,7 @@ class CommandCSEnforce : public Command void DoRestricted(CommandSource &source, ChanServ::Channel *ci) { bool override = !source.AccessFor(ci).HasPriv("AKICK") && source.HasPriv("chanserv/access/modify"); - Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "to enforce restricted"; + logger.Command(override ? LogType::OVERRIDE : LogType::COMMAND, source, ci, _("{source} used {command} on {channel} to enforce restricted")); std::vector users; for (Channel::ChanUserList::iterator it = ci->c->users.begin(), it_end = ci->c->users.end(); it != it_end; ++it) @@ -82,7 +82,7 @@ class CommandCSEnforce : public Command void DoRegOnly(CommandSource &source, ChanServ::Channel *ci) { bool override = !source.AccessFor(ci).HasPriv("AKICK") && source.HasPriv("chanserv/access/modify"); - Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "to enforce registered only"; + logger.Command(override ? LogType::OVERRIDE : LogType::COMMAND, source, ci, _("{source} used {command} on {channel} to enforce registered only")); std::vector users; for (Channel::ChanUserList::iterator it = ci->c->users.begin(), it_end = ci->c->users.end(); it != it_end; ++it) @@ -114,7 +114,7 @@ class CommandCSEnforce : public Command void DoSSLOnly(CommandSource &source, ChanServ::Channel *ci) { bool override = !source.AccessFor(ci).HasPriv("AKICK") && source.HasPriv("chanserv/access/modify"); - Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "to enforce SSL only"; + logger.Command(override ? LogType::OVERRIDE : LogType::COMMAND, source, ci, _("{source} used {command} on {channel} to enforce SSL only")); std::vector users; for (Channel::ChanUserList::iterator it = ci->c->users.begin(), it_end = ci->c->users.end(); it != it_end; ++it) @@ -146,7 +146,7 @@ class CommandCSEnforce : public Command void DoBans(CommandSource &source, ChanServ::Channel *ci) { bool override = !source.AccessFor(ci).HasPriv("AKICK") && source.HasPriv("chanserv/access/modify"); - Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "to enforce bans"; + logger.Command(override ? LogType::OVERRIDE : LogType::COMMAND, source, ci, _("{source} used {command} on {channel} to enforce bans")); std::vector users; for (Channel::ChanUserList::iterator it = ci->c->users.begin(), it_end = ci->c->users.end(); it != it_end; ++it) @@ -175,7 +175,7 @@ class CommandCSEnforce : public Command void DoLimit(CommandSource &source, ChanServ::Channel *ci) { bool override = !source.AccessFor(ci).HasPriv("AKICK") && source.HasPriv("chanserv/access/modify"); - Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "to enforce limit"; + logger.Command(override ? LogType::OVERRIDE : LogType::COMMAND, source, ci, _("{source} used {command} on {channel} to enforce limit")); Anope::string l_str; if (!ci->c->GetParam("LIMIT", l_str)) diff --git a/modules/chanserv/entrymsg.cpp b/modules/chanserv/entrymsg.cpp index c739ba46a..b2edbc56f 100644 --- a/modules/chanserv/entrymsg.cpp +++ b/modules/chanserv/entrymsg.cpp @@ -151,7 +151,9 @@ class CommandEntryMessage : public Command msg->SetChannel(ci); msg->SetCreator(source.GetNick()); msg->SetMessage(message); - Log(source.AccessFor(ci).HasPriv("SET") ? LOG_COMMAND : LOG_OVERRIDE, source, this, ci) << "to add a message"; + + logger.Command(source.AccessFor(ci).HasPriv("SET") ? LogType::COMMAND : LogType::OVERRIDE, source, ci, _("{source} used {command} on {channel} to add a message")); + source.Reply(_("Entry message added to \002{0}\002"), ci->GetName()); } @@ -177,7 +179,9 @@ class CommandEntryMessage : public Command if (i > 0 && i <= messages.size()) { messages[i - 1]->Delete(); - Log(source.AccessFor(ci).HasPriv("SET") ? LOG_COMMAND : LOG_OVERRIDE, source, this, ci) << "to remove a message"; + + logger.Command(source.AccessFor(ci).HasPriv("SET") ? LogType::COMMAND : LogType::OVERRIDE, source, ci, _("{source} used {command} on {channel} to remove a message")); + source.Reply(_("Entry message \002{0}\002 for \002{1]\002 deleted."), i, ci->GetName()); } else @@ -192,9 +196,10 @@ class CommandEntryMessage : public Command void DoClear(CommandSource &source, ChanServ::Channel *ci) { for (EntryMsg *e : ci->GetRefs()) - delete e; + e->Delete(); + + logger.Command(source.AccessFor(ci).HasPriv("SET") ? LogType::COMMAND : LogType::OVERRIDE, source, ci, _("{source} used {command} on {channel} to remove all messages")); - Log(source.AccessFor(ci).HasPriv("SET") ? LOG_COMMAND : LOG_OVERRIDE, source, this, ci) << "to remove all messages"; source.Reply(_("Entry messages for \002{0}\002 have been cleared."), ci->GetName()); } diff --git a/modules/chanserv/flags.cpp b/modules/chanserv/flags.cpp index 4732aff5b..d87863be0 100644 --- a/modules/chanserv/flags.cpp +++ b/modules/chanserv/flags.cpp @@ -266,9 +266,12 @@ class CommandCSFlags : public Command if (current != NULL) { EventManager::Get()->Dispatch(&Event::AccessDel::OnAccessDel, ci, source, current); - delete current; - Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "to delete " << mask; - source.Reply(_("\002{0}\002 removed from the access list of \002{1}\002."), mask, ci->GetName()); + + logger.Command(override ? LogType::OVERRIDE : LogType::COMMAND, source, ci, _("{source} used {command} on {channel} to delete {0}"), current->Mask()); + + source.Reply(_("\002{0}\002 removed from the access list of \002{1}\002."), current->Mask(), ci->GetName()); + + current->Delete(); } else { @@ -290,11 +293,12 @@ class CommandCSFlags : public Command access->SetFlags(Anope::string(current_flags.begin(), current_flags.end())); if (current != NULL) - delete current; + current->Delete(); EventManager::Get()->Dispatch(&Event::AccessAdd::OnAccessAdd, ci, source, access); - Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "to modify " << mask << "'s flags to " << access->AccessSerialize(); + logger.Command(override ? LogType::OVERRIDE : LogType::COMMAND, source, ci, _("{source} used {command} on {channel} to modify flags of {0} to {1}"), access->Mask(), access->AccessSerialize()); + if (p != NULL) { if (add) @@ -303,7 +307,9 @@ class CommandCSFlags : public Command source.Reply(_("Privilege \002{0}\002 removed from \002{1}\002 on \002{2}\002, new flags are +\002{3}\002"), p->name, access->Mask(), ci->GetName(), access->AccessSerialize()); } else + { source.Reply(_(