summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAdam <Adam@anope.org>2017-01-23 12:35:14 -0500
committerAdam <Adam@anope.org>2017-01-23 12:35:14 -0500
commit16ca76c2e7ab287e480185fbb03a0bb438351eda (patch)
treedfb25534afa2352b65b2ee707086cb5eecc96fbb /src
parentff030c1eb7c3764f9add2a689479e84d616cabcb (diff)
Make log system use newer format strings
Also allow log messages to be translatable
Diffstat (limited to 'src')
-rw-r--r--src/bots.cpp6
-rw-r--r--src/channels.cpp67
-rw-r--r--src/command.cpp39
-rw-r--r--src/config.cpp16
-rw-r--r--src/extensible.cpp2
-rw-r--r--src/init.cpp100
-rw-r--r--src/language.cpp17
-rw-r--r--src/logger.cpp445
-rw-r--r--src/mail.cpp4
-rw-r--r--src/main.cpp11
-rw-r--r--src/misc.cpp43
-rw-r--r--src/modes.cpp12
-rw-r--r--src/module.cpp20
-rw-r--r--src/modulemanager.cpp42
-rw-r--r--src/process.cpp22
-rw-r--r--src/serialize.cpp32
-rw-r--r--src/servers.cpp16
-rw-r--r--src/service_manager.cpp8
-rw-r--r--src/socket_clients.cpp8
-rw-r--r--src/socketengines/socketengine_epoll.cpp2
-rw-r--r--src/socketengines/socketengine_kqueue.cpp2
-rw-r--r--src/socketengines/socketengine_poll.cpp2
-rw-r--r--src/socketengines/socketengine_select.cpp2
-rw-r--r--src/sockets.cpp2
-rw-r--r--src/uplink.cpp30
-rw-r--r--src/users.cpp36
-rw-r--r--src/xline.cpp2
27 files changed, 573 insertions, 415 deletions
diff --git a/src/bots.cpp b/src/bots.cpp
index dfe46ea67..86d0a0136 100644
--- a/src/bots.cpp
+++ b/src/bots.cpp
@@ -31,11 +31,13 @@
#include "event.h"
#include "modules/chanserv.h"
-ServiceBot::ServiceBot(const Anope::string &nnick, const Anope::string &nuser, const Anope::string &nhost, const Anope::string &nreal, const Anope::string &bmodes) : LocalUser(nnick, nuser, nhost, "", "", Me, nreal, Anope::CurTime, "", IRCD ? IRCD->UID_Retrieve() : "", NULL), botmodes(bmodes)
+ServiceBot::ServiceBot(const Anope::string &nnick, const Anope::string &nuser, const Anope::string &nhost, const Anope::string &nreal, const Anope::string &bmodes)
+ : LocalUser(nnick, nuser, nhost, "", "", Me, nreal, Anope::CurTime, "", IRCD ? IRCD->UID_Retrieve() : "", NULL)
+ , botmodes(bmodes)
+ , logger(this)
{
this->type = UserType::BOT;
this->lastmsg = Anope::CurTime;
- this->introduced = false;
EventManager::Get()->Dispatch(&Event::CreateBot::OnCreateBot, this);
diff --git a/src/channels.cpp b/src/channels.cpp
index aed6c7b53..2b9ea438d 100644
--- a/src/channels.cpp
+++ b/src/channels.cpp
@@ -36,19 +36,16 @@ channel_map ChannelList;
std::vector<Channel *> Channel::deleting;
Channel::Channel(const Anope::string &nname, time_t ts)
+ : logger(this)
{
if (nname.empty())
throw CoreException("A channel without a name ?");
this->name = nname;
-
this->creation_time = ts;
- this->syncing = this->botchannel = false;
- this->server_modetime = this->chanserv_modetime = 0;
- this->server_modecount = this->chanserv_modecount = this->bouncy_modes = this->topic_ts = this->topic_time = 0;
if (Me && Me->IsSynced())
- Log(NULL, this, "create");
+ logger.Category("create").Log("Channel {0} was created", this->GetName());
EventManager::Get()->Dispatch(&Event::ChannelCreate::OnChannelCreate, this);
}
@@ -60,7 +57,7 @@ Channel::~Channel()
ModeManager::StackerDel(this);
if (Me && Me->IsSynced())
- Log(NULL, this, "destroy");
+ logger.Category("destroy").Log("Channel {0} was destroyed", this->GetName());
if (this->ci)
this->ci->c = NULL;
@@ -68,6 +65,11 @@ Channel::~Channel()
ChannelList.erase(this->name);
}
+const Anope::string &Channel::GetName() const
+{
+ return name;
+}
+
void Channel::Reset()
{
this->modes.clear();
@@ -113,7 +115,7 @@ void Channel::CheckModes()
/* Check for mode bouncing */
if (this->chanserv_modetime == Anope::CurTime && this->server_modetime == Anope::CurTime && this->server_modecount >= 3 && this->chanserv_modecount >= 3)
{
- Log() << "Warning: unable to set modes on channel " << this->name << ". Are your servers' U:lines configured correctly?";
+ Anope::Logger.Log("Warning: unable to set modes on channel {0}. Are your servers' U:lines configured correctly?", this->GetName());
this->bouncy_modes = 1;
return;
}
@@ -143,7 +145,7 @@ bool Channel::CheckDelete()
ChanUserContainer* Channel::JoinUser(User *user, const ChannelStatus *status)
{
if (user->server && user->server->IsSynced())
- Log(user, this, "join");
+ logger.Category("join").Log(_("{0} joined {1}"), user->GetMask(), this->GetName());
ChanUserContainer *cuc = new ChanUserContainer(user, this);
user->chans[this] = cuc;
@@ -157,16 +159,16 @@ ChanUserContainer* Channel::JoinUser(User *user, const ChannelStatus *status)
void Channel::DeleteUser(User *user)
{
if (user->server && user->server->IsSynced() && !user->Quitting())
- Log(user, this, "leave");
+ logger.Category("leave").Log(_("{0} left {1}"), user->GetMask(), this->GetName());
EventManager::Get()->Dispatch(&Event::LeaveChannel::OnLeaveChannel, user, this);
ChanUserContainer *cu = user->FindChannel(this);
if (!this->users.erase(user))
- Log(LOG_DEBUG) << "Channel::DeleteUser() tried to delete non-existent user " << user->nick << " from channel " << this->name;
+ logger.Debug("Channel::DeleteUser() tried to delete non-existent user {0} from channel {1}", user->GetMask(), this->GetName());
if (!user->chans.erase(this))
- Log(LOG_DEBUG) << "Channel::DeleteUser() tried to delete non-existent channel " << this->name << " from " << user->nick << "'s channel list";
+ logger.Debug("Channel::DeleteUser() tried to delete non-existent channel {0} from channel list of user {1}", this->GetName(), user->GetMask());
delete cu;
QueueForDeletion();
@@ -273,7 +275,7 @@ void Channel::SetModeInternal(const MessageSource &setter, ChannelMode *ocm, con
{
if (param.empty())
{
- Log() << "Channel::SetModeInternal() mode " << cm->mchar << " with no parameter for channel " << this->name;
+ Anope::Logger.Log("Channel::SetModeInternal() mode {} with no parameter for channel {}", cm->mchar, this->GetName());
return;
}
@@ -281,11 +283,11 @@ void Channel::SetModeInternal(const MessageSource &setter, ChannelMode *ocm, con
if (!u)
{
- Log() << "MODE " << this->name << " +" << cm->mchar << " for non-existent user " << param;
+ Anope::Logger.Debug("Mode +{0} for non-existent user {1} on channel {2}", cm->mchar, param, this->GetName());
return;
}
- Log(LOG_DEBUG) << "Setting +" << cm->mchar << " on " << this->name << " for " << u->nick;
+ Anope::Logger.Debug("Setting +{0} on {1} for {2}", cm->mchar, this->GetName(), u->GetMask());
/* Set the status on the user */
ChanUserContainer *cc = u->FindChannel(this);
@@ -309,7 +311,7 @@ void Channel::SetModeInternal(const MessageSource &setter, ChannelMode *ocm, con
if (param.empty() && cm->type != MODE_REGULAR)
{
- Log() << "Channel::SetModeInternal() mode " << cm->mchar << " for " << this->name << " with no paramater, but is a param mode";
+ Anope::Logger.Log("Channel::SetModeInternal() mode {0} for {1} with no paramater, but is a param mode", cm->mchar, this->name);
return;
}
@@ -337,7 +339,7 @@ void Channel::RemoveModeInternal(const MessageSource &setter, ChannelMode *ocm,
{
if (param.empty())
{
- Log() << "Channel::RemoveModeInternal() mode " << cm->mchar << " with no parameter for channel " << this->name;
+ Anope::Logger.Log("Channel::RemoveModeInternal() mode {0} with no parameter for channel {1}", cm->mchar, this->GetName());
return;
}
@@ -345,11 +347,11 @@ void Channel::RemoveModeInternal(const MessageSource &setter, ChannelMode *ocm,
if (!u)
{
- Log() << "Channel::RemoveModeInternal() MODE " << this->name << "-" << cm->mchar << " for non-existent user " << param;
+ Anope::Logger.Debug("Mode -{0} for non-existent user {1} on channel {2}", cm->mchar, param, this->GetName());
return;
}
- Log(LOG_DEBUG) << "Setting -" << cm->mchar << " on " << this->name << " for " << u->nick;
+ Anope::Logger.Debug("Setting -{0} on {1} for {2}", cm->mchar, this->GetName(), u->GetMask());
/* Remove the status on the user */
ChanUserContainer *cc = u->FindChannel(this);
@@ -592,12 +594,12 @@ void Channel::SetModesInternal(MessageSource &source, const Anope::string &mode,
;
else if (ts > this->creation_time)
{
- Log(LOG_DEBUG) << "Dropping mode " << mode << " on " << this->name << ", " << ts << " > " << this->creation_time;
+ Anope::Logger.Debug("Dropping mode {0} on {1}, TS {2] > {3}", mode, this->GetName(), ts, this->creation_time);
return;
}
else if (ts < this->creation_time)
{
- Log(LOG_DEBUG) << "Changing TS of " << this->name << " from " << this->creation_time << " to " << ts;
+ Anope::Logger.Debug("Changing TS of {0} from {1} to {2}", this->GetName(), this->creation_time, ts);
this->creation_time = ts;
this->Reset();
}
@@ -635,7 +637,7 @@ void Channel::SetModesInternal(MessageSource &source, const Anope::string &mode,
cm = ModeManager::FindChannelModeByChar(m[i]);
if (!cm)
{
- Log(LOG_DEBUG) << "Channel::SetModeInternal: Unknown mode char " << m[i];
+ Anope::Logger.Debug("Channel::SetModeInternal: Unknown mode char {0}", m[i]);
continue;
}
modestring += cm->mchar;
@@ -678,7 +680,9 @@ void Channel::SetModesInternal(MessageSource &source, const Anope::string &mode,
this->RemoveModeInternal(source, cm, token, enforce_mlock);
}
else
- Log() << "warning: Channel::SetModesInternal() received more modes requiring params than params, modes: " << mode;
+ {
+ Anope::Logger.Log("warning: Channel::SetModesInternal() received more modes requiring params than params, modes: {0}", mode);
+ }
}
if (!this_reference)
@@ -696,9 +700,9 @@ void Channel::SetModesInternal(MessageSource &source, const Anope::string &mode,
}
if (setter)
- Log(setter, this, "mode") << modestring << paramstring;
+ logger.Category("mode").Log("{0} {1}", modestring, paramstring);
else
- Log(LOG_DEBUG) << source.GetName() << " is setting " << this->name << " to " << modestring << paramstring;
+ logger.Debug("{0} is setting {1] to {2}{3}", source.GetName(), this->GetName(), modestring, paramstring);
if (enforce_mlock)
this->CheckModes();
@@ -724,23 +728,24 @@ bool Channel::KickInternal(const MessageSource &source, const Anope::string &nic
{
User *sender = source.GetUser();
User *target = User::Find(nick);
+
if (!target)
{
- Log(LOG_DEBUG) << "Channel::KickInternal got a nonexistent user " << nick << " on " << this->name << ": " << reason;
+ Anope::Logger.Debug("Channel::KickInternal got a nonexistent user {0} on {1}: {2}", nick, this->GetName(), reason);
return false;
}
if (sender)
- Log(sender, this, "kick") << "kicked " << target->nick << " (" << reason << ")";
+ logger.User(sender).Category("kick").Log(_("{0} kicked {1} from {2} ({3})"), sender->GetMask(), target->GetMask(), this->GetName(), reason);
else
- Log(target, this, "kick") << "was kicked by " << source.GetName() << " (" << reason << ")";
+ logger.Category("kick").Log(_("{0} kicked {1} from {2} ({3})"), source.GetName(), target->GetMask(), this->GetName(), reason);
Anope::string chname = this->name;
ChanUserContainer *cu = target->FindChannel(this);
if (cu == NULL)
{
- Log(LOG_DEBUG) << "Channel::KickInternal got kick for user " << target->nick << " from " << source.GetSource() << " who isn't on channel " << this->name;
+ Anope::Logger.Debug("Kick for user {0} who is not in channel {1}", target->GetMask(), this->GetName());
return false;
}
@@ -778,7 +783,7 @@ void Channel::ChangeTopicInternal(User *u, const Anope::string &user, const Anop
this->topic_ts = ts;
this->topic_time = Anope::CurTime;
- Log(LOG_DEBUG) << "Topic of " << this->name << " changed by " << this->topic_setter << " to " << newtopic;
+ Anope::Logger.Debug("Topic of {0} changed by {1} to {2}", this->GetName(), this->topic_setter, newtopic);
EventManager::Get()->Dispatch(&Event::TopicUpdated::OnTopicUpdated, u, this, user, this->topic);
}
@@ -805,7 +810,7 @@ void Channel::SetCorrectModes(User *user, bool give_modes)
if (!this->ci)
return;
- Log(LOG_DEBUG) << "Setting correct user modes for " << user->nick << " on " << this->name << " (" << (give_modes ? "" : "not ") << "giving modes)";
+ Anope::Logger.Debug("Setting correct user modes for {0} on {1} ({2}giving modes)", user->nick, this->name, give_modes ? "" : "not ");
ChanServ::AccessGroup u_access = ci->AccessFor(user);
@@ -892,7 +897,7 @@ bool Channel::CheckKick(User *user)
if (reason.empty())
reason = Language::Translate(user->Account(), _("You are not permitted to be on this channel."));
- Log(LOG_DEBUG) << "Autokicking " << user->nick << " (" << mask << ") from " << this->name;
+ Anope::Logger.Debug("Autokicking {0} ({1}) from {2}", user->nick, mask, this->name);
this->SetMode(NULL, "BAN", mask);
this->Kick(NULL, user, reason);
diff --git a/src/command.cpp b/src/command.cpp
index 7a87b07f3..9095c0526 100644
--- a/src/command.cpp
+++ b/src/command.cpp
@@ -31,8 +31,12 @@
#include "modules/botserv.h"
#include "modules/chanserv.h"
-CommandSource::CommandSource(const Anope::string &n, User *user, NickServ::Account *core, CommandReply *r, ServiceBot *bi) : nick(n), u(user), nc(core), reply(r),
- c(NULL), service(bi)
+CommandSource::CommandSource(const Anope::string &n, User *user, NickServ::Account *core, CommandReply *r, ServiceBot *bi)
+ : nick(n)
+ , u(user)
+ , nc(core)
+ , reply(r)
+ , service(bi)
{
}
@@ -51,6 +55,24 @@ NickServ::Account *CommandSource::GetAccount()
return this->nc;
}
+Anope::string CommandSource::GetSource()
+{
+ if (u)
+ if (nc)
+ return this->u->GetMask() + " (" + this->nc->GetDisplay() + ")";
+ else
+ return this->u->GetMask();
+ else if (nc)
+ return nc->GetDisplay();
+ else
+ return this->nick;
+}
+
+const Anope::string &CommandSource::GetCommand() const
+{
+ return this->command;
+}
+
ChanServ::AccessGroup CommandSource::AccessFor(ChanServ::Channel *ci)
{
if (this->u)
@@ -120,9 +142,12 @@ void CommandSource::Reply(const Anope::string &message)
this->reply->SendMessage(*this->service, tok);
}
-Command::Command(Module *o, const Anope::string &sname, size_t minparams, size_t maxparams) : Service(o, NAME, sname), max_params(maxparams), min_params(minparams), module(o)
+Command::Command(Module *o, const Anope::string &sname, size_t minparams, size_t maxparams) : Service(o, NAME, sname)
+ , max_params(maxparams)
+ , min_params(minparams)
+ , module(o)
+ , logger(this)
{
- allow_unregistered = require_user = false;
}
Command::~Command()
@@ -234,7 +259,7 @@ void Command::Run(CommandSource &source, const Anope::string &message)
source.Reply(_("Unknown command \002{0}\002. \"{1}{2} HELP\" for help."), message, Config->StrictPrivmsg, source.service->nick);
else
source.Reply(_("Unknown command \002{0}\002."), message);
- Log(source.service) << "Command " << it->first << " exists on me, but its service " << info.name << " was not found!";
+ source.service->logger.Log("Command {0} exists on me, but its service {1} was not found!", it->first, info.name);
return;
}
@@ -260,7 +285,7 @@ void Command::Run(CommandSource &source, const Anope::string &cmdname, const Com
{
source.Reply(_("Password authentication required for that command."));
if (source.GetUser())
- Log(LOG_NORMAL, "access_denied_unreg", source.service) << "Access denied for unregistered user " << source.GetUser()->GetMask() << " with command " << cmdname;
+ Anope::Logger.User(source.service).Category("access_denied_unreg").Log(_("Access denied for unregistered user {0} with command {1}"), source.GetUser()->GetMask(), cmdname);
return;
}
@@ -285,7 +310,7 @@ void Command::Run(CommandSource &source, const Anope::string &cmdname, const Com
else
source.Reply(_("Access denied. You do not have access to command \002{0}\002."), info.permission);
if (source.GetUser())
- Log(LOG_NORMAL, "access_denied", source.service) << "Access denied for user " << source.GetUser()->GetMask() << " with command " << cmdname;
+ Anope::Logger.User(source.service).Category("access_denied").Log(_("Access denied for user {0} with command {1}"), source.GetUser()->GetMask(), cmdname);
return;
}
diff --git a/src/config.cpp b/src/config.cpp
index e34177e8f..fbac466d9 100644
--- a/src/config.cpp
+++ b/src/config.cpp
@@ -307,7 +307,7 @@ Conf::Conf() : Block("")
if (ot2->GetName().equals_ci(str))
{
- Log() << "Inheriting commands and privs from " << ot2->GetName() << " to " << ot->GetName();
+ Anope::Logger.Log(_("Inheriting commands and privs from {0} to {1}"), ot2->GetName(), ot->GetName());
ot->Inherits(ot2);
break;
}
@@ -528,7 +528,7 @@ Conf::Conf() : Block("")
/* Check the user keys */
if (!options->Get<unsigned>("seed"))
- Log() << "Configuration option options:seed should be set. It's for YOUR safety! Remember that!";
+ Anope::Logger.Log(_("Configuration option options:seed should be set. It's for YOUR safety! Remember that!"));
/* check regexengine */
const Anope::string &regex_engine = options->Get<Anope::string>("regexengine");
@@ -725,7 +725,7 @@ void Conf::LoadOpers()
ot = this->MyOperTypes[j];
if (ot == NULL)
{
- Log() << "Oper block for " << nname << " has invalid oper type " << type;
+ Anope::Logger.Log(_("Oper block for {0} has invalid oper type {1}"), nname, type);
continue;
}
@@ -741,7 +741,7 @@ void Conf::LoadOpers()
o->SetHost(host);
o->SetVhost(vhost);
- Log(LOG_DEBUG) << "Creating oper " << nname << " of type " << ot->GetName();
+ Anope::Logger.Debug(_("Creating oper {0} of type {1}"), nname, ot->GetName());
}
/* Apply new opers */
@@ -752,7 +752,7 @@ void Conf::LoadOpers()
continue;
na->GetAccount()->SetOper(o);
- Log() << "Tied oper " << na->GetAccount()->GetDisplay() << " to type " << o->GetType()->GetName();
+ Anope::Logger.Log(_("Tied oper {0} to type {1}"), na->GetAccount()->GetDisplay(), o->GetType()->GetName());
}
}
@@ -896,7 +896,7 @@ void Conf::LoadConf(File &file)
int linenumber = 0;
bool in_word = false, in_quote = false, in_comment = false;
- Log(LOG_DEBUG) << "Start to read conf " << file.GetName();
+ Anope::Logger.Debug("Start to read conf {0}", file.GetName());
// Start reading characters...
while (!file.End())
{
@@ -907,7 +907,7 @@ void Conf::LoadConf(File &file)
if (line.empty() && in_quote)
wordbuffer += "\n";
- for (unsigned c = 0, len = line.length(); c < len; ++c)
+ for (unsigned int c = 0, len = line.length(); c < len; ++c)
{
char ch = line[c];
if (in_quote)
@@ -1056,7 +1056,7 @@ void Conf::LoadConf(File &file)
Block *b = block_stack.top();
if (b)
- Log(LOG_DEBUG) << "ln " << linenumber << " EOL: s='" << b->name << "' '" << itemname << "' set to '" << wordbuffer << "'";
+ Anope::Logger.Debug("ln {0} EOL: s='{1}' '{2}' set to '{3}'", linenumber, b->name, itemname, wordbuffer);
/* Check defines */
for (int i = 0; i < this->CountBlock("define"); ++i)
diff --git a/src/extensible.cpp b/src/extensible.cpp
index dc468fae7..524d74be3 100644
--- a/src/extensible.cpp
+++ b/src/extensible.cpp
@@ -39,7 +39,7 @@ bool Extensible::HasExtOK(const Anope::string &name)
if (ref)
return ref->HasExt(this);
- Log(LOG_DEBUG) << "HasExt for nonexistent type " << name << " on " << static_cast<const void *>(this);
+ Anope::Logger.Debug("HasExt for nonexistent type {0} on {1}", name, static_cast<const void *>(this));
return false;
}
diff --git a/src/init.cpp b/src/init.cpp
index 92cc70e9a..2922edaf1 100644
--- a/src/init.cpp
+++ b/src/init.cpp
@@ -144,18 +144,18 @@ void Anope::HandleSignal()
}
catch (const ConfigException &ex)
{
- Log() << "Error reloading configuration file: " << ex.GetReason();
+ Anope::Logger.Log("Error reloading configuration file: {0}", ex.GetReason());
}
break;
}
case SIGTERM:
case SIGINT:
#ifndef _WIN32
- Log() << "Received " << strsignal(Signal) << " signal (" << Signal << "), exiting.";
+ Anope::Logger.Log(_("Received {0} signal ({1}), exiting"), strsignal(Signal), Signal);
Anope::QuitReason = Anope::string("Services terminating via signal ") + strsignal(Signal) + " (" + stringify(Signal) + ")";
#else
- Log() << "Received signal " << Signal << ", exiting.";
- Anope::QuitReason = Anope::string("Services terminating via signal ") + stringify(Signal);
+ Anope::Logger.Log(_("Received signal {0}, exiting"), Signal);
+ Anope::QuitReason = "Services terminating via signal " + stringify(Signal);
#endif
Anope::Quitting = true;
break;
@@ -248,7 +248,7 @@ static void setuidgid()
errno = 0;
struct passwd *u = getpwnam(options->Get<Anope::string>("user").c_str());
if (u == NULL)
- Log() << "Unable to setuid to " << options->Get<Anope::string>("user") << ": " << Anope::LastError();
+ Anope::Logger.Log(_("Unable to setuid to {0}: {1}"), options->Get<Anope::string>("user"), Anope::LastError());
else
uid = u->pw_uid;
}
@@ -257,7 +257,7 @@ static void setuidgid()
errno = 0;
struct group *g = getgrnam(options->Get<Anope::string>("group").c_str());
if (g == NULL)
- Log() << "Unable to setgid to " << options->Get<Anope::string>("group") << ": " << Anope::LastError();
+ Anope::Logger.Log(_("Unable to setgid to {0}: {1}"), options->Get<Anope::string>("group"), Anope::LastError());
else
gid = g->gr_gid;
}
@@ -277,16 +277,16 @@ static void setuidgid()
if (static_cast<int>(gid) != -1)
{
if (setgid(gid) == -1)
- Log() << "Unable to setgid to " << options->Get<Anope::string>("group") << ": " << Anope::LastError();
+ Anope::Logger.Log(_("Unable to setgid to {0}: {1}"), options->Get<Anope::string>("group"), Anope::LastError());
else
- Log() << "Successfully set group to " << options->Get<Anope::string>("group");
+ Anope::Logger.Log(_("Successfully set group to {0"), options->Get<Anope::string>("group"));
}
if (static_cast<int>(uid) != -1)
{
if (setuid(uid) == -1)
- Log() << "Unable to setuid to " << options->Get<Anope::string>("user") << ": " << Anope::LastError();
+ Anope::Logger.Log(_("Unable to setuid to {0}: {1}"), options->Get<Anope::string>("user"), Anope::LastError());
else
- Log() << "Successfully set user to " << options->Get<Anope::string>("user");
+ Anope::Logger.Log(_("Successfully set user to {0}"), options->Get<Anope::string>("user"));
}
#endif
}
@@ -303,33 +303,33 @@ void Anope::Init(int ac, char **av)
if (GetCommandLineArgument("version", 'v'))
{
- Log(LOG_TERMINAL) << "Anope-" << Anope::Version() << " -- Built: " << Anope::VersionBuildTime() << " -- Flags: " << Anope::VersionFlags();
+ Anope::Logger.Terminal(_("Anope-{0} -- Built: {1} -- Flags: {2}"), Anope::Version(), Anope::VersionBuildTime(), Anope::VersionFlags());
exit(EXIT_SUCCESS);
}
if (GetCommandLineArgument("help", 'h'))
{
- Log(LOG_TERMINAL) << "Anope-" << Anope::Version();
- Log(LOG_TERMINAL) << "Anope IRC Services (https://anope.org)";
- Log(LOG_TERMINAL) << "Usage ./" << Anope::ServicesBin << " [options] ...";
- Log(LOG_TERMINAL) << "-c, --config=filename.conf";
- Log(LOG_TERMINAL) << " --confdir=conf file direcory";
- Log(LOG_TERMINAL) << " --dbdir=database directory";
- Log(LOG_TERMINAL) << "-d, --debug[=level]";
- Log(LOG_TERMINAL) << "-h, --help";
- Log(LOG_TERMINAL) << " --localedir=locale directory";
- Log(LOG_TERMINAL) << " --logdir=logs directory";
- Log(LOG_TERMINAL) << " --modulesdir=modules directory";
- Log(LOG_TERMINAL) << "-e, --noexpire";
- Log(LOG_TERMINAL) << "-n, --nofork";
- Log(LOG_TERMINAL) << " --nothird";
- Log(LOG_TERMINAL) << " --protocoldebug";
- Log(LOG_TERMINAL) << "-r, --readonly";
- Log(LOG_TERMINAL) << "-s, --support";
- Log(LOG_TERMINAL) << "-v, --version";
- Log(LOG_TERMINAL) << "";
- Log(LOG_TERMINAL) << "Further support is available from https://anope.org";
- Log(LOG_TERMINAL) << "Or visit us on IRC at irc.anope.org #anope";
+ Anope::Logger.Terminal(_("Anope-{0}"), Anope::Version());
+ Anope::Logger.Terminal(_("Anope IRC Services (https://anope.org)"));
+ Anope::Logger.Terminal(_("Usage ./{0} [options] ..."), Anope::ServicesBin);
+ Anope::Logger.Terminal(_("-c, --config=filename.conf"));
+ Anope::Logger.Terminal(_(" --confdir=conf file direcory"));
+ Anope::Logger.Terminal(_(" --dbdir=database directory"));
+ Anope::Logger.Terminal(_("-d, --debug[=level]"));
+ Anope::Logger.Terminal(_("-h, --help"));
+ Anope::Logger.Terminal(_(" --localedir=locale directory"));
+ Anope::Logger.Terminal(_(" --logdir=logs directory"));
+ Anope::Logger.Terminal(_(" --modulesdir=modules directory"));
+ Anope::Logger.Terminal(_("-e, --noexpire"));
+ Anope::Logger.Terminal(_("-n, --nofork"));
+ Anope::Logger.Terminal(_(" --nothird"));
+ Anope::Logger.Terminal(_(" --protocoldebug"));
+ Anope::Logger.Terminal(_("-r, --readonly"));
+ Anope::Logger.Terminal(_("-s, --support"));
+ Anope::Logger.Terminal(_("-v, --version"));
+ Anope::Logger.Terminal("");
+ Anope::Logger.Terminal(_("Further support is available from https://anope.org"));
+ Anope::Logger.Terminal(_("Or visit us on IRC at irc.anope.org #anope"));
exit(EXIT_SUCCESS);
}
@@ -417,7 +417,7 @@ void Anope::Init(int ac, char **av)
throw CoreException("Unable to chdir to " + Anope::ServicesDir + ": " + Anope::LastError());
}
- Log(LOG_TERMINAL) << "Anope-" << Anope::Version() << " -- Built: " << Anope::VersionBuildTime() << " -- Flags: " << Anope::VersionFlags();
+ Anope::Logger.Terminal("Anope-{0} -- Built: {1} -- Flags: {2}", Anope::Version(), Anope::VersionBuildTime(), Anope::VersionFlags());
#ifdef _WIN32
if (!SupportedWindowsVersion())
@@ -439,9 +439,9 @@ void Anope::Init(int ac, char **av)
#endif
#ifdef _WIN32
- Log(LOG_TERMINAL) << "Using configuration file " << Anope::ConfigDir << "\\" << ServicesConf.GetName();
+ Anope::Logger.Terminal("Using configuration file {0}\\{1}", Anope::ConfigDir, ServicesConf.GetName());
#else
- Log(LOG_TERMINAL) << "Using configuration file " << Anope::ConfigDir << "/" << ServicesConf.GetName();
+ Anope::Logger.Terminal("Using configuration file {0}/{1}", Anope::ConfigDir, ServicesConf.GetName());
/* Fork to background */
if (!Anope::NoFork)
@@ -471,7 +471,7 @@ void Anope::Init(int ac, char **av)
}
else if (i == -1)
{
- Log() << "Error, unable to fork: " << Anope::LastError();
+ Anope::Logger.Terminal("Error, unable to fork: {0}", Anope::LastError());
Anope::NoFork = true;
}
@@ -499,11 +499,11 @@ void Anope::Init(int ac, char **av)
}
catch (const ConfigException &ex)
{
- Log(LOG_TERMINAL) << ex.GetReason();
- Log(LOG_TERMINAL) << "*** Support resources: Read through the anope.conf self-contained";
- Log(LOG_TERMINAL) << "*** documentation. Read the documentation files found in the 'docs'";
- Log(LOG_TERMINAL) << "*** folder. Visit our portal located at https://anope.org/. Join";
- Log(LOG_TERMINAL) << "*** our support channel on irc.anope.org #anope.";
+ Anope::Logger.Terminal(ex.GetReason());
+ Anope::Logger.Terminal("*** Support resources: Read through the anope.conf self-contained");
+ Anope::Logger.Terminal("*** documentation. Read the documentation files found in the 'docs'");
+ Anope::Logger.Terminal("*** folder. Visit our portal located at https://anope.org/. Join");
+ Anope::Logger.Terminal("*** our support channel on irc.anope.org #anope.");
throw CoreException("Configuration file failed to validate");
}
@@ -522,7 +522,12 @@ void Anope::Init(int ac, char **av)
}
/* Announce ourselves to the logfile. */
- Log() << "Anope " << Anope::Version() << " starting up" << (Anope::Debug || Anope::ReadOnly ? " (options:" : "") << (Anope::Debug ? " debug" : "") << (Anope::ReadOnly ? " readonly" : "") << (Anope::Debug || Anope::ReadOnly ? ")" : "");
+ if (Anope::Debug || Anope::ReadOnly)
+ Anope::Logger.Log("Anope {0} starting up ({1})",
+ Anope::Version(),
+ Anope::Format("options:{0}{1}", Anope::Debug ? " debug" : "", Anope::ReadOnly ? " readonly" : ""));
+ else
+ Anope::Logger.Log("Anope {0} starting up", Anope::Version());
InitSignals();
@@ -536,7 +541,7 @@ void Anope::Init(int ac, char **av)
ModeManager::Apply(nullptr);
/* load modules */
- Log() << "Loading modules...";
+ Anope::Logger.Log("Loading modules...");
for (int i = 0; i < Config->CountBlock("module"); ++i)
ModuleManager::LoadModule(Config->GetBlock("module", i)->Get<Anope::string>("name"), NULL);
@@ -556,7 +561,7 @@ void Anope::Init(int ac, char **av)
/* Write our PID to the PID file. */
write_pidfile();
- Log() << "Using IRCd protocol " << protocol->name;
+ Anope::Logger.Log("Using IRCd protocol {0}", protocol->GetName());
/* Auto assign sid if applicable */
if (IRCD->RequiresID)
@@ -576,10 +581,9 @@ void Anope::Init(int ac, char **av)
}
/* Load up databases */
- Log() << "Loading databases...";
- EventReturn MOD_RESULT = EventManager::Get()->Dispatch(&Event::LoadDatabase::OnLoadDatabase);;
- static_cast<void>(MOD_RESULT);
- Log() << "Databases loaded";
+ Anope::Logger.Log("Loading databases...");
+ EventManager::Get()->Dispatch(&Event::LoadDatabase::OnLoadDatabase);;
+ Anope::Logger.Log("Databases loaded");
for (channel_map::const_iterator it = ChannelList.begin(), it_end = ChannelList.end(); it != it_end; ++it)
it->second->Sync();
diff --git a/src/language.cpp b/src/language.cpp
index 8c3e6221a..238449aaa 100644
--- a/src/language.cpp
+++ b/src/language.cpp
@@ -34,14 +34,14 @@ std::vector<Anope::string> Language::Domains;
void Language::InitLanguages()
{
#if GETTEXT_FOUND
- Log(LOG_DEBUG) << "Initializing Languages...";
+ Anope::Logger.Debug("Initializing Languages...");
Languages.clear();
if (!bindtextdomain("anope", Anope::LocaleDir.c_str()))
- Log() << "Error calling bindtextdomain, " << Anope::LastError();
+ Anope::Logger.Log("Error calling bindtextdomain, {0}", Anope::LastError());
else
- Log(LOG_DEBUG) << "Successfully bound anope to " << Anope::LocaleDir;
+ Anope::Logger.Debug("Successfully bound anope to {0}", Anope::LocaleDir);
setlocale(LC_ALL, "");
@@ -52,15 +52,15 @@ void Language::InitLanguages()
const Anope::string &lang_name = Translate(language.c_str(), _("English"));
if (lang_name == "English")
{
- Log() << "Unable to use language " << language;
+ Anope::Logger.Log("Unable to use language {0}", language);
continue;
}
- Log(LOG_DEBUG) << "Found language " << language;
+ Anope::Logger.Debug("Found language {0}", language);
Languages.push_back(language);
}
#else
- Log() << "Unable to initialize languages, gettext is not installed";
+ Anope::Logger.Log("Unable to initialize languages, gettext is not installed");
#endif
}
@@ -109,7 +109,12 @@ const char *Language::Translate(const char *lang, const char *string)
return "";
if (!lang || !*lang)
+ {
+ if (Config == nullptr)
+ return string;
+
lang = Config->DefLanguage.c_str();
+ }
#ifdef __USE_GNU_GETTEXT
++_nl_msg_cat_cntr;
diff --git a/src/logger.cpp b/src/logger.cpp
index 2751382f6..f6e961ee8 100644
--- a/src/logger.cpp
+++ b/src/logger.cpp
@@ -29,6 +29,7 @@
#include "uplink.h"
#include "protocol.h"
#include "event.h"
+#include "anope.h"
#include "modules/nickserv.h"
#include "modules/chanserv.h"
@@ -57,7 +58,9 @@ static Anope::string GetTimeStamp()
strftime(s, sizeof(tbuf) - (s - tbuf) - 1, " %Y]", &tm);
}
else
+ {
strftime(tbuf, sizeof(tbuf) - 1, "[%b %d %H:%M:%S %Y]", &tm);
+ }
return tbuf;
}
@@ -85,161 +88,7 @@ const Anope::string &LogFile::GetName() const
return this->filename;
}
-Log::Log(LogType t, const Anope::string &cat, ServiceBot *b) : bi(b), u(NULL), nc(NULL), c(NULL), source(NULL), chan(NULL), ci(NULL), s(NULL), m(NULL), type(t), category(cat)
-{
-}
-
-Log::Log(LogType t, CommandSource &src, Command *_c, ChanServ::Channel *_ci) : u(src.GetUser()), nc(src.nc), c(_c), source(&src), chan(NULL), ci(_ci), s(NULL), m(NULL), type(t)
-{
- if (!c)
- throw CoreException("Invalid pointers passed to Log::Log");
-
- if (type != LOG_COMMAND && type != LOG_OVERRIDE && type != LOG_ADMIN)
- throw CoreException("This constructor does not support this log type");
-
- size_t sl = c->GetName().find('/');
- this->bi = NULL;
- if (sl != Anope::string::npos)
- this->bi = ServiceBot::Find(c->GetName().substr(0, sl), true);
- this->category = c->GetName();
-}
-
-Log::Log(User *_u, Channel *ch, const Anope::string &cat) : bi(NULL), u(_u), nc(NULL), c(NULL), source(NULL), chan(ch), ci(chan ? *chan->ci : NULL), s(NULL), m(NULL), type(LOG_CHANNEL), category(cat)
-{
- if (!chan)
- throw CoreException("Invalid pointers passed to Log::Log");
-}
-
-Log::Log(User *_u, const Anope::string &cat, ServiceBot *_bi) : bi(_bi), u(_u), nc(NULL), c(NULL), source(NULL), chan(NULL), ci(NULL), s(NULL), m(NULL), type(LOG_USER), category(cat)
-{
- if (!u)
- throw CoreException("Invalid pointers passed to Log::Log");
-}
-
-Log::Log(Server *serv, const Anope::string &cat, ServiceBot *_bi) : bi(_bi), u(NULL), nc(NULL), c(NULL), source(NULL), chan(NULL), ci(NULL), s(serv), m(NULL), type(LOG_SERVER), category(cat)
-{
- if (!s)
- throw CoreException("Invalid pointer passed to Log::Log");
-}
-
-Log::Log(ServiceBot *b, const Anope::string &cat) : bi(b), u(NULL), nc(NULL), c(NULL), source(NULL), chan(NULL), ci(NULL), s(NULL), m(NULL), type(LOG_NORMAL), category(cat)
-{
-}
-
-Log::Log(Module *mod, const Anope::string &cat, ServiceBot *_bi) : bi(_bi), u(NULL), nc(NULL), c(NULL), source(NULL), chan(NULL), ci(NULL), s(NULL), m(mod), type(LOG_MODULE), category(cat)
-{
-}
-
-Log::~Log()
-{
- if (Anope::NoFork && Anope::Debug && this->type >= LOG_NORMAL && this->type <= LOG_DEBUG + Anope::Debug - 1)
- std::cout << GetTimeStamp() << " Debug: " << this->BuildPrefix() << this->buf.str() << std::endl;
- else if (Anope::NoFork && this->type <= LOG_TERMINAL)
- std::cout << GetTimeStamp() << " " << this->BuildPrefix() << this->buf.str() << std::endl;
- else if (this->type == LOG_TERMINAL)
- std::cout << this->BuildPrefix() << this->buf.str() << std::endl;
-
- /* Some of the higher debug messages are in the event/service system which manages event dispatch,
- * so firing off the log event here can cause them to be in weird states
- */
- if (this->type <= LOG_NORMAL)
- {
- EventManager *em = EventManager::Get();
- if (em != nullptr)
- em->Dispatch(&Event::Log::OnLog, this);
- }
-
- if (Config)
- for (unsigned i = 0; i < Config->LogInfos.size(); ++i)
- if (Config->LogInfos[i].HasType(this->type, this->category))
- Config->LogInfos[i].ProcessMessage(this);
-}
-
-Anope::string Log::FormatSource() const
-{
- if (u)
- if (nc)
- return this->u->GetMask() + " (" + this->nc->GetDisplay() + ")";
- else
- return this->u->GetMask();
- else if (nc)
- return nc->GetDisplay();
- return "";
-}
-
-Anope::string Log::FormatCommand() const
-{
- Anope::string buffer = FormatSource() + " used " + (source != NULL && !source->command.empty() ? source->command : this->c->GetName()) + " ";
- if (this->ci)
- buffer += "on " + this->ci->GetName() + " ";
-
- return buffer;
-}
-
-Anope::string Log::BuildPrefix() const
-{
- Anope::string buffer;
-
- switch (this->type)
- {
- case LOG_ADMIN:
- {
- if (!this->c)
- break;
- buffer += "ADMIN: " + FormatCommand();
- break;
- }
- case LOG_OVERRIDE:
- {
- if (!this->c)
- break;
- buffer += "OVERRIDE: " + FormatCommand();
- break;
- }
- case LOG_COMMAND:
- {
- if (!this->c)
- break;
- buffer += "COMMAND: " + FormatCommand();
- break;
- }
- case LOG_CHANNEL:
- {
- if (!this->chan)
- break;
- buffer += "CHANNEL: ";
- Anope::string src = FormatSource();
- if (!src.empty())
- buffer += src + " ";
- buffer += this->category + " " + this->chan->name + " ";
- break;
- }
- case LOG_USER:
- {
- if (this->u)
- buffer += "USERS: " + FormatSource() + " ";
- break;
- }
- case LOG_SERVER:
- {
- if (this->s)
- buffer += "SERVER: " + this->s->GetName() + " (" + this->s->GetDescription() + ") ";
- break;
- }
- case LOG_MODULE:
- {
- if (this->m)
- buffer += this->m->name.upper() + ": ";
- break;
- }
- default:
- break;
- }
-
- return buffer;
-}
-
-LogInfo::LogInfo(int la, bool rio, bool ldebug) : bot(NULL), last_day(0), log_age(la), raw_io(rio), debug(ldebug)
+LogInfo::LogInfo(int la, bool rio, bool ldebug) : log_age(la), raw_io(rio), debug(ldebug)
{
}
@@ -250,41 +99,44 @@ LogInfo::~LogInfo()
this->logfiles.clear();
}
-bool LogInfo::HasType(LogType ltype, const Anope::string &type) const
+bool LogInfo::HasType(LogType ltype, LogLevel level, const Anope::string &type) const
{
+ switch (level)
+ {
+ case LogLevel::TERMINAL:
+ return true;
+ case LogLevel::RAWIO:
+ return (Anope::Debug || this->debug) ? true : this->raw_io;
+ case LogLevel::DEBUG:
+ return Anope::Debug ? true : this->debug;
+ case LogLevel::DEBUG_2:
+ case LogLevel::DEBUG_3:
+ return;
+ }
+
const std::vector<Anope::string> *list = NULL;
switch (ltype)
{
- case LOG_ADMIN:
+ case LogType::ADMIN:
list = &this->admin;
break;
- case LOG_OVERRIDE:
+ case LogType::OVERRIDE:
list = &this->override;
break;
- case LOG_COMMAND:
+ case LogType::COMMAND:
list = &this->commands;
break;
- case LOG_SERVER:
+ case LogType::SERVER:
list = &this->servers;
break;
- case LOG_CHANNEL:
+ case LogType::CHANNEL:
list = &this->channels;
break;
- case LOG_USER:
+ case LogType::USER:
list = &this->users;
break;
- case LOG_TERMINAL:
- return true;
- case LOG_RAWIO:
- return (Anope::Debug || this->debug) ? true : this->raw_io;
- case LOG_DEBUG:
- return Anope::Debug ? true : this->debug;
- case LOG_DEBUG_2:
- case LOG_DEBUG_3:
- case LOG_DEBUG_4:
- break;
- case LOG_MODULE:
- case LOG_NORMAL:
+ case LogType::MODULE:
+ case LogType::NORMAL:
default:
list = &this->normal;
break;
@@ -293,7 +145,7 @@ bool LogInfo::HasType(LogType ltype, const Anope::string &type) const
if (list == NULL)
return false;
- for (unsigned i = 0; i < list->size(); ++i)
+ for (unsigned int i = 0; i < list->size(); ++i)
{
Anope::string cat = list->at(i);
bool inverse = false;
@@ -327,7 +179,7 @@ void LogInfo::OpenLogFiles()
LogFile *lf = new LogFile(CreateLogName(target));
if (!lf->stream.is_open())
{
- Log() << "Unable to open logfile " << lf->GetName();
+ Anope::Logger.Log("Unable to open logfile {0}", lf->GetName());
delete lf;
}
else
@@ -335,7 +187,7 @@ void LogInfo::OpenLogFiles()
}
}
-void LogInfo::ProcessMessage(const Log *l)
+void LogInfo::ProcessMessage(const Logger *l, const Anope::string &message)
{
if (!this->sources.empty())
{
@@ -344,26 +196,29 @@ void LogInfo::ProcessMessage(const Log *l)
{
const Anope::string &src = this->sources[i];
- if (l->bi && src == l->bi->nick)
+ if (l->GetBot() && src == l->GetBot()->nick)
log = true;
- else if (l->u && src == l->u->nick)
+ else if (l->GetUser() && src == l->GetUser()->nick)
log = true;
- else if (l->nc && src == l->nc->GetDisplay())
+ else if (l->GetAccount() && src == l->GetAccount()->GetDisplay())
log = true;
- else if (l->ci && src == l->ci->GetName())
+ else if (l->GetCi() && src == l->GetCi()->GetName())
log = true;
- else if (l->m && src == l->m->name)
+ else if (l->GetModule() && src == l->GetModule()->name)
log = true;
- else if (l->s && src == l->s->GetName())
+ else if (l->GetServer() && src == l->GetServer()->GetName())
log = true;
}
if (!log)
return;
}
- const Anope::string &buffer = l->BuildPrefix() + l->buf.str();
+ const Anope::string &buffer = l->BuildPrefix() + message;
- EventManager::Get()->Dispatch(&Event::LogMessage::OnLogMessage, this, l, buffer);
+ if (l->GetLevel() <= LogLevel::NORMAL)
+ {
+ EventManager::Get()->Dispatch(&Event::LogMessage::OnLogMessage, this, l, buffer);
+ }
for (unsigned i = 0; i < this->targets.size(); ++i)
{
@@ -371,13 +226,13 @@ void LogInfo::ProcessMessage(const Log *l)
if (!target.empty() && target[0] == '#')
{
- if (UplinkSock && l->type <= LOG_NORMAL && Me && Me->IsSynced())
+ if (UplinkSock && l->type == LogType::NORMAL && Me && Me->IsSynced())
{
Channel *c = Channel::Find(target);
if (!c)
continue;
- User *bi = l->bi;
+ User *bi = l->GetBot();
if (!bi)
bi = this->bot;
if (!bi)
@@ -388,9 +243,9 @@ void LogInfo::ProcessMessage(const Log *l)
}
else if (target == "opers")
{
- if (UplinkSock && l->bi && l->type <= LOG_NORMAL && Me && Me->IsSynced())
+ if (UplinkSock && l->GetBot() && l->type == LogType::NORMAL && Me && Me->IsSynced())
{
- IRCD->SendWallops(l->bi, buffer);
+ IRCD->SendWallops(l->GetBot(), buffer);
}
}
}
@@ -413,7 +268,7 @@ void LogInfo::ProcessMessage(const Log *l)
if (IsFile(oldlog))
{
unlink(oldlog.c_str());
- Log(LOG_DEBUG) << "Deleted old logfile " << oldlog;
+ Anope::Logger.Debug("Deleted old logfile {0}", oldlog);
}
}
}
@@ -425,3 +280,213 @@ void LogInfo::ProcessMessage(const Log *l)
}
}
+void Logger::InsertVariables(FormatInfo &fi)
+{
+ if (user != nullptr)
+ fi.Add("user"_kw = user->GetMask());
+
+ if (ci != nullptr)
+ fi.Add("channel"_kw = ci->GetName());
+ else if (channel != nullptr)
+ fi.Add("channel"_kw = channel->GetName());
+
+ fi.Add("source"_kw = this->FormatSource());
+
+ if (source != nullptr && !source->GetCommand().empty())
+ fi.Add("command"_kw = source->GetCommand());
+ else if (command != nullptr)
+ fi.Add("command"_kw = command->GetName());
+}
+
+Anope::string Logger::FormatSource() const
+{
+ if (user)
+ if (account)
+ return user->GetMask() + " (" + account->GetDisplay() + ")";
+ else
+ return user->GetMask();
+ else if (account)
+ return account->GetDisplay();
+ else if (source)
+ return source->GetNick();
+ return "";
+}
+
+Anope::string Logger::BuildPrefix() const
+{
+ switch (this->type)
+ {
+ case LogType::ADMIN:
+ return "ADMIN: ";
+ case LogType::OVERRIDE:
+ return "OVERRIDE: ";
+ case LogType::COMMAND:
+ return "COMMAND: ";
+ case LogType::SERVER:
+ return "SERVER: ";
+ case LogType::CHANNEL:
+ return "CHANNEL: ";
+ case LogType::USER:
+ return "USER: ";
+ case LogType::MODULE:
+ return this->module != nullptr ? (this->module->name.upper() + ": ") : "";
+ }
+
+ return "";
+}
+
+void Logger::LogMessage(const Anope::string &message)
+{
+ if (Anope::NoFork && Anope::Debug && level >= LogLevel::NORMAL && static_cast<int>(level) <= static_cast<int>(LogLevel::DEBUG) + Anope::Debug - 1)
+ std::cout << GetTimeStamp() << " Debug: " << this->BuildPrefix() << message << std::endl;
+ else if (Anope::NoFork && level <= LogLevel::TERMINAL)
+ std::cout << GetTimeStamp() << " " << this->BuildPrefix() << message << std::endl;
+ else if (level == LogLevel::TERMINAL)
+ std::cout << this->BuildPrefix() << message << std::endl;
+
+ if (level <= LogLevel::NORMAL)
+ {
+ EventManager *em = EventManager::Get();
+ if (em != nullptr)
+ em->Dispatch(&Event::Log::OnLog, this);
+ }
+
+ if (Config != nullptr)
+ for (LogInfo &info : Config->LogInfos)
+ if (info.HasType(this->type, this->level, this->category))
+ info.ProcessMessage(this, message);
+}
+
+LogType Logger::GetType() const
+{
+ return type;
+}
+
+LogLevel Logger::GetLevel() const
+{
+ return level;
+}
+
+Module *Logger::GetModule() const
+{
+ return module;
+}
+
+Command *Logger::GetCommand() const
+{
+ return command;
+}
+
+ServiceBot *Logger::GetBot() const
+{
+ return bot;
+}
+
+Server *Logger::GetServer() const
+{
+ return server;
+}
+
+User *Logger::GetUser() const
+{
+ return user;
+}
+
+void Logger::SetUser(class User *u)
+{
+ user = u;
+}
+
+NickServ::Account *Logger::GetAccount() const
+{
+ return account;
+}
+
+void Logger::SetAccount(NickServ::Account *acc)
+{
+ account = acc;
+}
+
+Channel *Logger::GetChannel() const
+{
+ return channel;
+}
+
+void Logger::SetChannel(class Channel *c)
+{
+ channel = c;
+}
+
+ChanServ::Channel *Logger::GetCi() const
+{
+ return ci;
+}
+
+void Logger::SetCi(ChanServ::Channel *c)
+{
+ ci = c;
+}
+
+CommandSource *Logger::GetSource() const
+{
+ return source;
+}
+
+void Logger::SetSource(CommandSource *s)
+{
+ source = s;
+ if (s != nullptr)
+ {
+ SetUser(s->GetUser());
+ SetAccount(s->GetAccount());
+ SetChannel(s->c);
+ }
+}
+
+Logger Logger::Category(const Anope::string &c) const
+{
+ Logger l = *this;
+ l.category = c;
+ return l;
+}
+
+Logger Logger::User(class User *u) const
+{
+ Logger l = *this;
+ l.user = u;
+ return l;
+}
+
+Logger Logger::Channel(class Channel *c) const
+{
+ Logger l = *this;
+ l.channel = c;
+ return l;
+}
+
+Logger Logger::Channel(ChanServ::Channel *c) const
+{
+ Logger l = *this;
+ l.ci = c;
+ return l;
+}
+
+Logger Logger::Source(CommandSource *s) const
+{
+ Logger l = *this;
+ l.source = s;
+ return l;
+}
+
+Logger Logger::Bot(ServiceBot *bot) const
+{
+ Logger l = *this;
+ l.bot = bot;
+ return l;
+}
+
+Logger Logger::Bot(const Anope::string &bot) const
+{
+ return Bot(Config ? Config->GetClient(bot) : nullptr);
+}
+
diff --git a/src/mail.cpp b/src/mail.cpp
index 02a39bd13..51068178d 100644
--- a/src/mail.cpp
+++ b/src/mail.cpp
@@ -31,9 +31,9 @@ Mail::Message::Message(const Anope::string &sf, const Anope::string &mailto, con
Mail::Message::~Message()
{
if (success)
- Log(LOG_NORMAL, "mail") << "Successfully delivered mail for " << mail_to << " (" << addr << ")";
+ Anope::Logger.Category("mail").Log(_("Successfully delivered mail for {0} ({1})"), mail_to, addr);
else
- Log(LOG_NORMAL, "mail") << "Error delivering mail for " << mail_to << " (" << addr << ")";
+ Anope::Logger.Category("mail").Log(_("Error delivering mail for {0} ({1})"), mail_to, addr);
}
void Mail::Message::Run()
diff --git a/src/main.cpp b/src/main.cpp
index 5a97da7d8..b171c9794 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -43,6 +43,7 @@ sig_atomic_t Anope::Signal = 0;
bool Anope::Quitting = false;
bool Anope::Restarting = false;
Anope::string Anope::QuitReason;
+Logger Anope::Logger;
static Anope::string BinaryDir; /* Full path to services bin directory */
@@ -128,7 +129,7 @@ int main(int ac, char **av, char **envp)
}
catch (const CoreException &ex)
{
- Log() << ex.GetReason();
+ Anope::Logger.Log(ex.GetReason());
return -1;
}
@@ -138,7 +139,7 @@ int main(int ac, char **av, char **envp)
}
catch (const SocketException &ex)
{
- Log(LOG_TERMINAL) << "Unable to connect to uplink #" << (Anope::CurrentUplink + 1) << " (" << Config->Uplinks[Anope::CurrentUplink].host << ":" << Config->Uplinks[Anope::CurrentUplink].port << "): " << ex.GetReason();
+ Anope::Logger.Terminal(_("Unable to connect to uplink #{0} ({1}:{2}): {3}"), Anope::CurrentUplink + 1, Config->Uplinks[Anope::CurrentUplink].host, Config->Uplinks[Anope::CurrentUplink].port, ex.GetReason());
}
/* Set up timers */
@@ -148,7 +149,7 @@ int main(int ac, char **av, char **envp)
/*** Main loop. ***/
while (!Anope::Quitting)
{
- Log(LOG_DEBUG_2) << "Top of main loop";
+ Anope::Logger.Debug2("Top of main loop");
/* Process timers */
if (Anope::CurTime - last_check >= Config->TimeoutCheck)
@@ -175,7 +176,7 @@ int main(int ac, char **av, char **envp)
if (Anope::QuitReason.empty())
Anope::QuitReason = "Terminating, reason unknown";
- Log() << Anope::QuitReason;
+ Anope::Logger.Log(Anope::QuitReason);
delete UplinkSock;
@@ -196,7 +197,7 @@ int main(int ac, char **av, char **envp)
Anope::string sbin = "./" + Anope::ServicesBin;
av[0] = const_cast<char *>(sbin.c_str());
execve(Anope::ServicesBin.c_str(), av, envp);
- Log() << "Restart failed";
+ Anope::Logger.Log("Restart failed");
Anope::ReturnValue = -1;
}
diff --git a/src/misc.cpp b/src/misc.cpp
index 863bca2b7..939d06498 100644
--- a/src/misc.cpp
+++ b/src/misc.cpp
@@ -411,7 +411,7 @@ bool Anope::Match(const Anope::string &str, const Anope::string &mask, bool case
}
catch (const std::regex_error &error)
{
- Log(LOG_DEBUG) << error.what();
+ Anope::Logger.Debug(error.what());
}
}
@@ -697,7 +697,7 @@ Anope::string Anope::Resolve(const Anope::string &host, int type)
memset(&hints, 0, sizeof(hints));
hints.ai_family = type;
- Log(LOG_DEBUG_2) << "Resolver: BlockingQuery: Looking up " << host;
+ Anope::Logger.Debug2("Resolver: BlockingQuery: Looking up {0}", host);
addrinfo *addrresult = NULL;
if (getaddrinfo(host.c_str(), NULL, &hints, &addrresult) == 0)
@@ -705,7 +705,7 @@ Anope::string Anope::Resolve(const Anope::string &host, int type)
sockaddrs addr;
memcpy(&addr, addrresult->ai_addr, addrresult->ai_addrlen);
result = addr.addr();
- Log(LOG_DEBUG_2) << "Resolver: " << host << " -> " << result;
+ Anope::Logger.Debug2("Resolver: {0} -> {1}", host, result);
freeaddrinfo(addrresult);
}
@@ -728,3 +728,40 @@ Anope::string Anope::Random(size_t len)
return buf;
}
+const kwarg *FormatInfo::GetKwarg(const Anope::string &name) const
+{
+ for (const kwarg &kw : parameters)
+ if (kw.name == name)
+ return &kw;
+ return nullptr;
+}
+
+void FormatInfo::Format()
+{
+ size_t start = 0;
+ size_t s = format.find('{', start);
+
+ while (s != Anope::string::npos)
+ {
+ size_t e = format.find('}', s + 1);
+ if (e == Anope::string::npos)
+ break;
+
+ Anope::string key = format.substr(s + 1, e - s - 1);
+
+ // Find replacement for key
+ const kwarg *arg = GetKwarg(key);
+
+ format.erase(s, e - s + 1);
+ if (arg != nullptr)
+ format.insert(s, arg->value);
+
+ start = s + (arg != nullptr ? arg->value.length() : 0);
+ s = format.find('{', start);
+ }
+}
+
+const Anope::string &FormatInfo::GetFormat() const
+{
+ return format;
+}
diff --git a/src/modes.cpp b/src/modes.cpp
index 348ec4542..f845f7408 100644
--- a/src/modes.cpp
+++ b/src/modes.cpp
@@ -733,13 +733,13 @@ void ModeManager::Apply(Configuration::Conf *old)
ChannelMode *mode;
if (cm.list)
- Log(LOG_DEBUG) << "Creating channelmode list " << cm.name << " (" << cm.character << ")";
+ Anope::Logger.Log("Creating channelmode list {0} ({1})", cm.name, cm.character);
else if (cm.status)
- Log(LOG_DEBUG) << "Creating channelmode status " << cm.name << " (" << cm.character << ")";
+ Anope::Logger.Log("Creating channelmode status {0} ({1})", cm.name, cm.character);
else if (cm.param)
- Log(LOG_DEBUG) << "Creating channelmode param " << cm.name << " (" << cm.character << ")";
+ Anope::Logger.Log("Creating channelmode param {0} ({1})", cm.name, cm.character);
else
- Log(LOG_DEBUG) << "Creating channelmode " << cm.name << " (" << cm.character << ")";
+ Anope::Logger.Log("Creating channelmode {0} ({1})", cm.name, cm.character);
if (cm.list)
mode = new ChannelModeList(cm.name, cm.character);
@@ -761,7 +761,7 @@ void ModeManager::Apply(Configuration::Conf *old)
{
UserMode *mode;
- Log(LOG_DEBUG) << "Creating usermode " << um.name << " (" << um.character << ")";
+ Anope::Logger.Log("Creating usermode {0} ({1})", um.name, um.character);
if (um.param)
mode = new UserModeParam(um.name, um.character);
@@ -840,7 +840,7 @@ Entry::Entry(const Anope::string &m, const Anope::string &fh) : name(m), mask(fh
this->host = cidr_ip;
this->family = addr.family();
- Log(LOG_DEBUG) << "Ban " << mask << " has cidr " << this->cidr_len;
+ Anope::Logger.Log("Ban {0} has cidr {1}", mask, this->cidr_len);
}
}
catch (const ConvertException &) { }
diff --git a/src/module.cpp b/src/module.cpp
index 73ab9ad99..7269800d5 100644
--- a/src/module.cpp
+++ b/src/module.cpp
@@ -25,7 +25,10 @@
# include <libintl.h>
#endif
-Module::Module(const Anope::string &modname, const Anope::string &, ModType modtype) : name(modname), type(modtype)
+Module::Module(const Anope::string &modname, const Anope::string &, ModType modtype)
+ : name(modname)
+ , type(modtype)
+ , logger(this)
{
this->handle = NULL;
this->permanent = false;
@@ -33,7 +36,9 @@ Module::Module(const Anope::string &modname, const Anope::string &, ModType modt
this->SetVersion(Anope::Version());
if (type & VENDOR)
+ {
this->SetAuthor("Anope");
+ }
else
{
/* Not vendor implies third */
@@ -50,7 +55,7 @@ Module::Module(const Anope::string &modname, const Anope::string &, ModType modt
ModuleManager::Modules.push_back(this);
#if GETTEXT_FOUND
- for (unsigned i = 0; i < Language::Languages.size(); ++i)
+ for (unsigned int i = 0; i < Language::Languages.size(); ++i)
{
/* Remove .UTF-8 or any other suffix */
Anope::string lang;
@@ -59,10 +64,12 @@ Module::Module(const Anope::string &modname, const Anope::string &, ModType modt
if (Anope::IsFile(Anope::LocaleDir + "/" + lang + "/LC_MESSAGES/" + modname + ".mo"))
{
if (!bindtextdomain(this->name.c_str(), Anope::LocaleDir.c_str()))
- Log() << "Error calling bindtextdomain, " << Anope::LastError();
+ {
+ Anope::Logger.Log("Error calling bindtextdomain, {0}", Anope::LastError());
+ }
else
{
- Log() << "Found language file " << lang << " for " << modname;
+ Anope::Logger.Log("Found language file {0} for {1}", lang, modname);
Language::Domains.push_back(modname);
}
break;
@@ -87,6 +94,11 @@ Module::~Module()
#endif
}
+const Anope::string &Module::GetName() const
+{
+ return this->name;
+}
+
void Module::SetPermanent(bool state)
{
this->permanent = state;
diff --git a/src/modulemanager.cpp b/src/modulemanager.cpp
index 204421f34..d4883eccb 100644
--- a/src/modulemanager.cpp
+++ b/src/modulemanager.cpp
@@ -48,12 +48,12 @@ void ModuleManager::CleanupRuntimeDirectory()
{
Anope::string dirbuf = Anope::DataDir + "/runtime";
- Log(LOG_DEBUG) << "Cleaning out Module run time directory (" << dirbuf << ") - this may take a moment please wait";
+ Anope::Logger.Debug("Cleaning out Module run time directory ({0}) - this may take a moment please wait", dirbuf);
DIR *dirp = opendir(dirbuf.c_str());
if (!dirp)
{
- Log(LOG_DEBUG) << "Cannot open directory (" << dirbuf << ")";
+ Anope::Logger.Debug("Cannot open directory ({0})", dirbuf);
return;
}
@@ -104,7 +104,7 @@ static ModuleReturn moduleCopyFile(const Anope::string &name, Anope::string &out
output = tmp_output;
free(tmp_output);
- Log(LOG_DEBUG_2) << "Runtime module location: " << output;
+ Anope::Logger.Debug2("Runtime module location: {0}", output);
std::ofstream target(output.c_str(), std::ios_base::in | std::ios_base::binary);
if (!target.is_open())
@@ -139,7 +139,7 @@ ModuleReturn ModuleManager::LoadModule(const Anope::string &modname, User *u)
if (FindModule(modname))
return MOD_ERR_EXISTS;
- Log(LOG_DEBUG) << "Trying to load module: " << modname;
+ Anope::Logger.Debug("Trying to load module: {0}", modname);
#ifdef _WIN32
/* Generate the filename for the temporary copy of the module */
@@ -150,9 +150,9 @@ ModuleReturn ModuleManager::LoadModule(const Anope::string &modname, User *u)
if (ret != MOD_ERR_OK)
{
if (ret == MOD_ERR_NOEXIST)
- Log(LOG_TERMINAL) << "Error while loading " << modname << " (file does not exist)";
+ Anope::Logger.Terminal(_("Error while loading {0} (file does not exist)"), modname);
else if (ret == MOD_ERR_FILE_IO)
- Log(LOG_TERMINAL) << "Error while loading " << modname << " (file IO error, check file permissions and diskspace)";
+ Anope::Logger.Terminal(_("Error while loading {0} (file IO error, check file permissions and diskspace)"), modname);
return ret;
}
#else
@@ -165,7 +165,7 @@ ModuleReturn ModuleManager::LoadModule(const Anope::string &modname, User *u)
if (!handle)
{
if (err && *err)
- Log() << err;
+ Anope::Logger.Log(err);
return MOD_ERR_NOLOAD;
}
@@ -174,9 +174,9 @@ ModuleReturn ModuleManager::LoadModule(const Anope::string &modname, User *u)
err = dlerror();
if (!module || module->api_version != ANOPE_MODAPI_VER)
{
- Log() << "No module symbols function found, not an Anope module";
+ Anope::Logger.Log("No module symbols function found, not an Anope module");
if (err && *err)
- Log(LOG_DEBUG) << err;
+ Anope::Logger.Log(err);
dlclose(handle);
return MOD_ERR_NOLOAD;
}
@@ -187,31 +187,31 @@ ModuleReturn ModuleManager::LoadModule(const Anope::string &modname, User *u)
if (v.GetMajor() < Anope::VersionMajor() || (v.GetMajor() == Anope::VersionMajor() && v.GetMinor() < Anope::VersionMinor()))
{
- Log() << "Module " << modname << " is compiled against an older version of Anope " << v.GetMajor() << "." << v.GetMinor() << ", this is " << Anope::VersionShort();
+ Anope::Logger.Log(_("Module {0} is compiled against an older version of Anope {1}.{2}, this is {3}"), modname, v.GetMajor(), v.GetMinor(), Anope::VersionShort());
dlclose(handle);
return MOD_ERR_VERSION;
}
else if (v.GetMajor() > Anope::VersionMajor() || (v.GetMajor() == Anope::VersionMajor() && v.GetMinor() > Anope::VersionMinor()))
{
- Log() << "Module " << modname << " is compiled against a newer version of Anope " << v.GetMajor() << "." << v.GetMinor() << ", this is " << Anope::VersionShort();
+ Anope::Logger.Log(_("Module {0} is compiled against a newer version of Anope {1}.{2}, this is {3}"), modname, v.GetMajor(), v.GetMinor(), Anope::VersionShort());
dlclose(handle);
return MOD_ERR_VERSION;
}
else if (v.GetPatch() < Anope::VersionPatch())
{
- Log() << "Module " << modname << " is compiled against an older version of Anope, " << v.GetMajor() << "." << v.GetMinor() << "." << v.GetPatch() << ", this is " << Anope::VersionShort();
+ Anope::Logger.Log(_("Module {0} is compiled against an older version of Anope, {1}.{2}.{3}, this is {4}"), modname, v.GetMajor(), v.GetMinor(), v.GetPatch(), Anope::VersionShort());
dlclose(handle);
return MOD_ERR_VERSION;
}
else if (v.GetPatch() > Anope::VersionPatch())
{
- Log() << "Module " << modname << " is compiled against a newer version of Anope, " << v.GetMajor() << "." << v.GetMinor() << "." << v.GetPatch() << ", this is " << Anope::VersionShort();
+ Anope::Logger.Log(_("Module {0} is compiled against a newer version of Anope, {1}.{2}.{3}, this is {4}"), modname, v.GetMajor(), v.GetMinor(), v.GetPatch(), Anope::VersionShort());
dlclose(handle);
return MOD_ERR_VERSION;
}
else
{
- Log(LOG_DEBUG_2) << "Module " << modname << " is compiled against current version of Anope " << Anope::VersionShort();
+ Anope::Logger.Debug2("Module {0} is compiled against current version of Anope {1}", Anope::VersionShort());
}
}
catch (const ModuleException &ex)
@@ -237,14 +237,14 @@ ModuleReturn ModuleManager::LoadModule(const Anope::string &modname, User *u)
}
catch (const ModuleException &ex)
{
- Log() << "Error while loading " << modname << ": " << ex.GetReason();
+ Anope::Logger.Log(_("Error while loading {0}: {1}"), modname, ex.GetReason());
moderr = MOD_ERR_EXCEPTION;
}
if (moderr != MOD_ERR_OK)
{
if (dlclose(handle))
- Log() << dlerror();
+ Anope::Logger.Log(dlerror());
return moderr;
}
@@ -260,12 +260,12 @@ ModuleReturn ModuleManager::LoadModule(const Anope::string &modname, User *u)
}
catch (const ModuleException &ex)
{
- Log() << "Module " << modname << " couldn't load:" << ex.GetReason();
+ Anope::Logger.Log(_("Module {0} couldn't load: {1}"), modname, ex.GetReason());
moderr = MOD_ERR_EXCEPTION;
}
catch (const ConfigException &ex)
{
- Log() << "Module " << modname << " couldn't load due to configuration problems: " << ex.GetReason();
+ Anope::Logger.Log(_("Module {0} couldn't load due to configuration problems: {1}"), modname, ex.GetReason());
moderr = MOD_ERR_EXCEPTION;
}
@@ -275,7 +275,7 @@ ModuleReturn ModuleManager::LoadModule(const Anope::string &modname, User *u)
return moderr;
}
- Log(LOG_DEBUG) << "Module " << modname << " loaded.";
+ Anope::Logger.Log(_("Module {0} loaded"), modname);
EventManager::Get()->Dispatch(&Event::ModuleLoad::OnModuleLoad, u, m);
@@ -352,7 +352,7 @@ ModuleReturn ModuleManager::DeleteModule(Module *m)
void *handle = m->handle;
Anope::string filename = m->filename;
- Log(LOG_DEBUG) << "Unloading module " << m->name;
+ Anope::Logger.Log("Unloading module {0}", m->name);
ModuleDef *def = m->def;
AnopeModule *module = m->module;
@@ -362,7 +362,7 @@ ModuleReturn ModuleManager::DeleteModule(Module *m)
dlerror();
if (dlclose(handle))
- Log() << dlerror();
+ Anope::Logger.Log(dlerror());
#ifdef _WIN32
if (!filename.empty())
diff --git a/src/process.cpp b/src/process.cpp
index 8512a188f..afb12b352 100644
--- a/src/process.cpp
+++ b/src/process.cpp
@@ -27,7 +27,7 @@
void Anope::Process(const Anope::string &buffer)
{
/* If debugging, log the buffer */
- Log(LOG_RAWIO) << "Received: " << buffer;
+ Anope::Logger.RawIO("Received: {0}", buffer);
if (buffer.empty())
return;
@@ -39,19 +39,19 @@ void Anope::Process(const Anope::string &buffer)
if (Anope::ProtocolDebug)
{
- Log() << "Source : " << (source.empty() ? "No source" : source);
- Log() << "Command: " << command;
+ Anope::Logger.Log("Source : {0}", source.empty() ? "No source" : source);
+ Anope::Logger.Log("Command: {0}", command);
if (params.empty())
- Log() << "No params";
+ Anope::Logger.Log("No params");
else
- for (unsigned i = 0; i < params.size(); ++i)
- Log() << "params " << i << ": " << params[i];
+ for (unsigned int i = 0; i < params.size(); ++i)
+ Anope::Logger.Log("params {0}: {1}", i, params[i]);
}
if (command.empty())
{
- Log(LOG_DEBUG) << "No command? " << buffer;
+ Anope::Logger.Debug("No command? {0}", buffer);
return;
}
@@ -77,16 +77,16 @@ void Anope::ProcessCommand(MessageSource &src, const Anope::string &command, con
buffer += " :" + params[params.size() - 1];
}
- Log(LOG_DEBUG) << "unknown command from server (" << buffer << ")";
+ Anope::Logger.Debug("unknown command from server ({0})", buffer);
return;
}
if (m->HasFlag(IRCDMESSAGE_SOFT_LIMIT) ? (params.size() < m->GetParamCount()) : (params.size() != m->GetParamCount()))
- Log(LOG_DEBUG) << "invalid parameters for " << command << ": " << params.size() << " != " << m->GetParamCount();
+ Anope::Logger.Debug("invalid parameters for {0}: {1} != {2}", command, params.size(), m->GetParamCount());
else if (m->HasFlag(IRCDMESSAGE_REQUIRE_USER) && !src.GetUser())
- Log(LOG_DEBUG) << "unexpected non-user source " << src.GetSource() << " for " << command;
+ Anope::Logger.Debug("unexpected non-user source {0} for {1}", src.GetSource(), command);
else if (m->HasFlag(IRCDMESSAGE_REQUIRE_SERVER) && !src.GetServer())
- Log(LOG_DEBUG) << "unexpected non-server source " << (src.GetSource().empty() ? "(no source)" : src.GetSource()) << " for " << command;
+ Anope::Logger.Debug("unexpected non-server source {0} for {1}", src.GetSource().empty() ? "(no source)" : src.GetSource(), command);
else
m->Run(src, params);
}
diff --git a/src/serialize.cpp b/src/serialize.cpp
index 4717c5948..d27950f36 100644
--- a/src/serialize.cpp
+++ b/src/serialize.cpp
@@ -56,7 +56,7 @@ void Serialize::GC()
continue;
}
- Log(LOG_DEBUG_2) << "garbage collected object " << o->id;
+ Anope::Logger.Debug2("garbage collected object {0}", o->id);
it = objects.erase(it);
delete o;
@@ -123,7 +123,7 @@ Object::Object(TypeBase *type)
type->objects.insert(this);
- Log(LOG_DEBUG_2) << "Creating object id #" << id << " address " << static_cast<void *>(this) << " type " << type->GetName();
+ Anope::Logger.Debug2("Creating object id #{0} address {1} type {2}", id, static_cast<void *>(this), type->GetName());
EventManager::Get()->Dispatch(&Event::SerializeEvents::OnSerializableCreate, this);
}
@@ -137,12 +137,12 @@ Object::Object(TypeBase *type, ID i)
type->objects.insert(this);
- Log(LOG_DEBUG_2) << "Creating object from id #" << id << " address " << static_cast<void *>(this) << " type " << type->GetName();
+ Anope::Logger.Debug2("Creating object from id #{0} address {1} type {2}", id, static_cast<void *>(this), type->GetName());
}
Object::~Object()
{
- Log(LOG_DEBUG_2) << "Destructing object id #" << id << " address " << static_cast<void *>(this) << " type " << s_type->GetName();
+ Anope::Logger.Debug2("Destructing object id #{0} address {2} type {3}", id, static_cast<void *>(this), s_type->GetName());
/* Remove in memory edges */
std::map<TypeBase *, std::vector<Edge>> copy = edges;
@@ -151,12 +151,12 @@ Object::~Object()
{
if (!edge.direction)
{
- Log(LOG_DEBUG_2) << "Removing edge from object id #" << edge.other->id << " type " << edge.other->GetSerializableType()->GetName() << " on field " << edge.field->serialize_name;
+ Anope::Logger.Debug2("Removing edge from object id #{0} type {1} on field {2}", edge.other->id, edge.other->GetSerializableType()->GetName(), edge.field->serialize_name);
edge.other->RemoveEdge(this, edge.field);
}
else
{
- Log(LOG_DEBUG_2) << "Removing edge to object id #" << edge.other->id << " type " << edge.other->GetSerializableType()->GetName() << " on field " << edge.field->serialize_name;
+ Anope::Logger.Debug2("Removing edge to object id #{0} type {1} on field {2}", edge.other->id, edge.other->GetSerializableType()->GetName(), edge.field->serialize_name);
this->RemoveEdge(edge.other, edge.field);
}
}
@@ -167,7 +167,7 @@ Object::~Object()
void Object::Delete()
{
- Log(LOG_DEBUG_2) << "Deleting object id #" << id << " type " << s_type->GetName();
+ Anope::Logger.Debug2("Deleting object id #{0} type {1}", id, s_type->GetName());
/* Delete dependant objects */
for (const Edge &edge : GetEdges(nullptr))
@@ -180,12 +180,12 @@ void Object::Delete()
if (field->depends)
{
- Log(LOG_DEBUG_2) << "Deleting dependent object #" << other->id << " type " << other->GetSerializableType()->GetName() << " due to edge on " << field->serialize_name;
+ Anope::Logger.Debug2("Deleting dependent object #{0} type {1} due to edge on {2}", other->id, other->GetSerializableType()->GetName(), field->serialize_name);
other->Delete();
}
else
{
- Log(LOG_DEBUG_2) << "Unsetting field " << field->serialize_name << " on object #" << other->id << " type " << other->GetSerializableType()->GetName();
+ Anope::Logger.Debug2("Unsetting field {0} on object #{1} type {2}", field->serialize_name, other->id, other->GetSerializableType()->GetName());
field->UnsetS(other);
}
}
@@ -210,7 +210,7 @@ void Object::RemoveEdge(Object *other, FieldBase *field)
if (it != myedges.end())
myedges.erase(it);
else
- Log(LOG_DEBUG_2) << "Unable to locate edge for removal on #" << this->id << " type " << s_type->GetName() << " -> #" << other->id << " type " << other->GetSerializableType()->GetName();
+ Anope::Logger.Debug2("Unable to locate edge for removal on #{0} type {1} -> #{2} type {3}", this->id, s_type->GetName(), other->id, other->GetSerializableType()->GetName());
if (myedges.empty())
this->edges.erase(other->GetSerializableType());
@@ -220,7 +220,7 @@ void Object::RemoveEdge(Object *other, FieldBase *field)
if (it != theiredges.end())
theiredges.erase(it);
else
- Log(LOG_DEBUG_2) << "Unable to locate edge for removal on #" << this->id << " type " << s_type->GetName() << " <- #" << other->id << " type " << other->GetSerializableType()->GetName();
+ Anope::Logger.Debug2("Unable to locate edge for removal on #{0} type {1} <- #{2} type {3}", this->id, s_type->GetName(), other->id, other->GetSerializableType()->GetName());
if (theiredges.empty())
other->edges.erase(this->GetSerializableType());
@@ -238,7 +238,7 @@ TypeBase::~TypeBase()
void TypeBase::Unregister()
{
- Log(LOG_DEBUG_2) << "Unregistering type " << this->GetName();
+ Anope::Logger.Debug2("Unregistering type {0}", this->GetName());
for (Object *obj : GetObjects<Object *>(this->GetName()))
obj->Delete();
@@ -259,7 +259,7 @@ Serialize::FieldBase *TypeBase::GetField(const Anope::string &fname)
if (fb->serialize_type == this->GetName() && fb->serialize_name == fname)
return fb;
- Log(LOG_DEBUG_2) << "GetField() for unknown field " << fname << " on " << this->GetName();
+ Anope::Logger.Debug2("GetField() for unknown field {0} on {1}", fname, this->GetName());
return nullptr;
}
@@ -303,7 +303,7 @@ FieldBase::~FieldBase()
void FieldBase::Unregister()
{
- Log(LOG_DEBUG_2) << "Unregistering field " << serialize_name << " on " << serialize_type;
+ Anope::Logger.Debug2("Unregistering field {0} on {1}", serialize_name, serialize_type);
/* find edges on this field */
for (Object *s : Serialize::GetObjects<Object *>(serialize_type))
@@ -312,7 +312,7 @@ void FieldBase::Unregister()
for (const Edge &edge : p.second)
if (edge.direction && edge.field == this)
{
- Log(LOG_DEBUG_2) << "Removing edge on #" << s->id << " type " << s->GetSerializableType()->GetName() << " -> #" << edge.other->id << " type " << edge.other->GetSerializableType()->GetName();
+ Anope::Logger.Debug2("Removing edge on #{0} type {1} -> #{2} type {3}", s->id, s->GetSerializableType()->GetName(), edge.other->id, edge.other->GetSerializableType()->GetName());
s->RemoveEdge(edge.other, edge.field);
goto cont;
@@ -334,7 +334,7 @@ std::vector<Serialize::TypeBase *> Serialize::GetTypes(const Anope::string &name
if (t != nullptr)
v.push_back(t);
else
- Log(LOG_DEBUG_2) << "GetTypes for unknown type " << name;
+ Anope::Logger.Debug2("GetTypes for unknown type {0}", name);
auto its = child_types.equal_range(name);
for (; its.first != its.second; ++its.first)
diff --git a/src/servers.cpp b/src/servers.cpp
index a04e36ded..7747f4a69 100644
--- a/src/servers.cpp
+++ b/src/servers.cpp
@@ -36,7 +36,7 @@ Anope::map<Server *> Servers::ByID;
std::set<Anope::string> Servers::Capab;
-Server::Server(Server *up, const Anope::string &sname, unsigned shops, const Anope::string &desc, const Anope::string &ssid, bool jupe) : name(sname), hops(shops), description(desc), sid(ssid), uplink(up), users(0)
+Server::Server(Server *up, const Anope::string &sname, unsigned int shops, const Anope::string &desc, const Anope::string &ssid, bool jupe) : name(sname), hops(shops), description(desc), sid(ssid), uplink(up), users(0)
{
syncing = true;
juped = jupe;
@@ -46,7 +46,7 @@ Server::Server(Server *up, const Anope::string &sname, unsigned shops, const Ano
if (!ssid.empty())
Servers::ByID[ssid] = this;
- Log(this, "connect") << "has connected to the network (uplinked to " << (this->uplink ? this->uplink->GetName() : "no uplink") << ")";
+ this->logger.Category("connect").Log(_("{0} has connected to the network (uplinked to {1})"), this->GetName(), this->uplink ? this->uplink->GetName() : "no uplink");
/* Add this server to our uplinks leaf list */
if (this->uplink)
@@ -63,7 +63,7 @@ Server::Server(Server *up, const Anope::string &sname, unsigned shops, const Ano
Server::~Server()
{
- Log(this, "quit") << "quit from " << (this->uplink ? this->uplink->GetName() : "no uplink") << " for " << this->quit_reason;
+ this->logger.Category("quit").Log(_("{0} quit from {1} for {2}"), this->GetName(), this->uplink ? this->uplink->GetName() : "no uplink", this->quit_reason);
for (user_map::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it)
{
@@ -76,7 +76,7 @@ Server::~Server()
}
}
- Log(LOG_DEBUG) << "Finished removing all users for " << this->GetName();
+ this->logger.Debug("Finished removing all users for {0}", this->GetName());
if (this->uplink)
this->uplink->DelLink(this);
@@ -207,7 +207,7 @@ void Server::AddLink(Server *s)
{
this->links.push_back(s);
- Log(this, "connect") << "introduced " << s->GetName();
+ this->logger.Category("connect").Log(_("{0} introduced {1}"), this->GetName(), s->GetName());
}
void Server::DelLink(Server *s)
@@ -224,7 +224,7 @@ void Server::DelLink(Server *s)
}
}
- Log(this, "quit") << "quit " << s->GetName();
+ this->logger.Category("quit").Log(_("{0} quit {1}"), this->GetName(), s->GetName());
}
void Server::Sync(bool sync_links)
@@ -234,7 +234,7 @@ void Server::Sync(bool sync_links)
syncing = false;
- Log(this, "sync") << "is done syncing";
+ this->logger.Category("sync").Log(_("{0} is done syncing"), this->GetName());
EventManager::Get()->Dispatch(&Event::ServerSync::OnServerSync, this);
@@ -269,7 +269,7 @@ void Server::Sync(bool sync_links)
if (!Anope::NoFork)
{
- Log(LOG_TERMINAL) << "Successfully linked, launching into background...";
+ Anope::Logger.Terminal(_("Successfully linked, launching into background..."));
Anope::Fork();
}
}
diff --git a/src/service_manager.cpp b/src/service_manager.cpp
index 4c8d2a072..aa2de8b07 100644
--- a/src/service_manager.cpp
+++ b/src/service_manager.cpp
@@ -83,7 +83,7 @@ void ServiceManager::Register(Service *service)
throw ModuleException("Service of type " + service->GetType() + " with name " + service->GetName() + " already exists from " + service->GetOwner()->name);
}
- Log(LOG_DEBUG_3) << "Service registered: " << service->GetType() << " " << service->GetName() << " address " << static_cast<void *>(this) << " by " << service->GetOwner();
+ Anope::Logger.Debug3("Service registered: {0} {1} address {2} by {3}", service->GetType(), service->GetName(), static_cast<void *>(this), service->GetOwner());
services.push_back(service);
@@ -92,7 +92,7 @@ void ServiceManager::Register(Service *service)
void ServiceManager::Unregister(Service *service)
{
- Log(LOG_DEBUG_3) << "Service unregistered: " << service->GetType() << " " << service->GetName() << " address " << static_cast<void *>(service) << " by " << service->GetOwner();
+ Anope::Logger.Debug3("Service unregistered: {0} {1} address {2} by {3}", service->GetType(), service->GetName(), static_cast<void *>(service), service->GetOwner());
auto it = std::find(services.begin(), services.end(), service);
if (it != services.end())
@@ -108,13 +108,13 @@ void ServiceManager::Lookup(ServiceReferenceBase *reference)
if (reference->GetName().empty())
{
std::vector<Service *> services = this->FindServices(reference->GetType());
- Log(LOG_DEBUG_3) << "Service lookup " << static_cast<void *>(reference) << " type " << reference->GetType() << " name " << reference->GetName() << ": " << services.size() << " services";
+ Anope::Logger.Debug3("Service lookup {0} type {1} name {2}: {3} services", static_cast<void *>(reference), reference->GetType(), reference->GetName(), services.size());
reference->SetServices(services);
}
else
{
Service *service = this->FindService(reference->GetType(), reference->GetName());
- Log(LOG_DEBUG_3) << "Service lookup " << static_cast<void *>(reference) << " type " << reference->GetType() << " name " << reference->GetName() << ": " << service;
+ Anope::Logger.Debug3("Service lookup {0} type {1} name {2}: {3}", static_cast<void *>(reference), reference->GetType(), reference->GetName(), service);
reference->SetService(service);
}
}
diff --git a/src/socket_clients.cpp b/src/socket_clients.cpp
index 278ba7c21..5c45cdf51 100644
--- a/src/socket_clients.cpp
+++ b/src/socket_clients.cpp
@@ -42,7 +42,7 @@ bool ConnectionSocket::Process()
}
catch (const SocketException &ex)
{
- Log() << ex.GetReason();
+ Anope::Logger.Log(ex.GetReason());
}
return false;
}
@@ -62,7 +62,7 @@ void ConnectionSocket::OnConnect()
void ConnectionSocket::OnError(const Anope::string &error)
{
- Log(LOG_DEBUG) << "Socket error: " << error;
+ Anope::Logger.Debug("Socket error: {0}", error);
}
ClientSocket::ClientSocket(ListenSocket *l, const sockaddrs &addr) : ls(l), clientaddr(addr)
@@ -82,7 +82,7 @@ bool ClientSocket::Process()
}
catch (const SocketException &ex)
{
- Log() << ex.GetReason();
+ Anope::Logger.Log(ex.GetReason());
}
return false;
}
@@ -102,6 +102,6 @@ void ClientSocket::OnAccept()
void ClientSocket::OnError(const Anope::string &error)
{
- Log(LOG_DEBUG) << "Socket error: " << error;
+ Anope::Logger.Debug("Socket error: {0}", error);
}
diff --git a/src/socketengines/socketengine_epoll.cpp b/src/socketengines/socketengine_epoll.cpp
index 3c0c22f40..314e1ec67 100644
--- a/src/socketengines/socketengine_epoll.cpp
+++ b/src/socketengines/socketengine_epoll.cpp
@@ -82,7 +82,7 @@ void SocketEngine::Process()
if (total == -1)
{
if (errno != EINTR)
- Log() << "SockEngine::Process(): error: " << Anope::LastError();
+ Anope::Logger.Log("SocketEngine::Process(): error: {0}", Anope::LastError());
return;
}
diff --git a/src/socketengines/socketengine_kqueue.cpp b/src/socketengines/socketengine_kqueue.cpp
index 5c5c99afe..a3f6d78aa 100644
--- a/src/socketengines/socketengine_kqueue.cpp
+++ b/src/socketengines/socketengine_kqueue.cpp
@@ -83,7 +83,7 @@ void SocketEngine::Process()
if (total == -1)
{
if (errno != EINTR)
- Log() << "SockEngine::Process(): error: " << Anope::LastError();
+ Anope::Logger.Log("SocketEngine::Process(): error: {0}", Anope::LastError());
return;
}
diff --git a/src/socketengines/socketengine_poll.cpp b/src/socketengines/socketengine_poll.cpp
index 422959df2..c469ed8e8 100644
--- a/src/socketengines/socketengine_poll.cpp
+++ b/src/socketengines/socketengine_poll.cpp
@@ -106,7 +106,7 @@ void SocketEngine::Process()
if (total < 0)
{
if (errno != EINTR)
- Log() << "SockEngine::Process(): error: " << Anope::LastError();
+ Anope::Logger.Log("SocketEngine::Process(): error: {0}", Anope::LastError());
return;
}
diff --git a/src/socketengines/socketengine_select.cpp b/src/socketengines/socketengine_select.cpp
index f1f4fb8d8..7987010ec 100644
--- a/src/socketengines/socketengine_select.cpp
+++ b/src/socketengines/socketengine_select.cpp
@@ -107,7 +107,7 @@ void SocketEngine::Process()
if (sresult == -1)
{
- Log() << "SockEngine::Process(): error: " << Anope::LastError();
+ Anope::Logger.Log("SocketEngine::Process(): error: {0}", Anope::LastError());
}
else if (sresult)
{
diff --git a/src/sockets.cpp b/src/sockets.cpp
index 70c9fef0d..ecdddfbb2 100644
--- a/src/sockets.cpp
+++ b/src/sockets.cpp
@@ -552,7 +552,7 @@ bool ListenSocket::ProcessRead()
}
catch (const SocketException &ex)
{
- Log() << ex.GetReason();
+ Anope::Logger.Log(ex.GetReason());
}
return true;
}
diff --git a/src/uplink.cpp b/src/uplink.cpp
index 1615eef9d..0f47788e7 100644
--- a/src/uplink.cpp
+++ b/src/uplink.cpp
@@ -42,7 +42,7 @@ class ReconnectTimer : public Timer
}
catch (const SocketException &ex)
{
- Log(LOG_TERMINAL) << "Unable to connect to uplink #" << (Anope::CurrentUplink + 1) << " (" << Config->Uplinks[Anope::CurrentUplink].host << ":" << Config->Uplinks[Anope::CurrentUplink].port << "): " << ex.GetReason();
+ Anope::Logger.Terminal(_("Unable to connect to uplink #{0} ({1}:{2}): {3}"), Anope::CurrentUplink + 1, Config->Uplinks[Anope::CurrentUplink].host, Config->Uplinks[Anope::CurrentUplink].port, ex.GetReason());
}
}
};
@@ -51,7 +51,7 @@ void Uplink::Connect()
{
if (Config->Uplinks.empty())
{
- Log() << "Warning: There are no configured uplinks.";
+ Anope::Logger.Log(_("Warning: There are no configured uplinks."));
return;
}
@@ -65,7 +65,7 @@ void Uplink::Connect()
UplinkSock->Bind(Config->GetBlock("serverinfo")->Get<Anope::string>("localhost"));
EventManager::Get()->Dispatch(&Event::PreServerConnect::OnPreServerConnect);
Anope::string ip = Anope::Resolve(u.host, u.ipv6 ? AF_INET6 : AF_INET);
- Log(LOG_TERMINAL) << "Attempting to connect to uplink #" << (Anope::CurrentUplink + 1) << " " << u.host << " (" << ip << "), port " << u.port;
+ Anope::Logger.Terminal(_("Attempting to connect to uplink #{0} {1} ({2}), port {3}"), Anope::CurrentUplink + 1, u.host, ip, u.port);
UplinkSock->Connect(ip, u.port);
}
@@ -82,9 +82,9 @@ UplinkSocket::~UplinkSocket()
this->OnError("");
Module *protocol = ModuleManager::FindFirstOf(PROTOCOL);
if (protocol && !protocol->name.find("inspircd"))
- Log(LOG_TERMINAL) << "Check that you have loaded m_spanningtree.so on InspIRCd, and are not connecting Anope to an SSL enabled port without configuring SSL in Anope (or vice versa)";
+ Anope::Logger.Terminal(_("Check that you have loaded m_spanningtree.so on InspIRCd, and are not connecting Anope to an SSL enabled port without configuring SSL in Anope (or vice versa)"));
else
- Log(LOG_TERMINAL) << "Check that you are not connecting Anope to an SSL enabled port without configuring SSL in Anope (or vice versa)";
+ Anope::Logger.Terminal(_("Check that you are not connecting Anope to an SSL enabled port without configuring SSL in Anope (or vice versa)"));
}
if (IRCD && Servers::GetUplink() && Servers::GetUplink()->IsSynced())
@@ -135,7 +135,7 @@ UplinkSocket::~UplinkSocket()
{
time_t retry = Config->GetBlock("options")->Get<time_t>("retrywait");
- Log() << "Disconnected, retrying in " << retry << " seconds";
+ Anope::Logger.Log(_("Disconnected, retrying in {0} seconds"), retry);
new ReconnectTimer(retry);
}
}
@@ -154,15 +154,17 @@ bool UplinkSocket::ProcessRead()
void UplinkSocket::OnConnect()
{
- Log(LOG_TERMINAL) << "Successfully connected to uplink #" << (Anope::CurrentUplink + 1) << " " << Config->Uplinks[Anope::CurrentUplink].host << ":" << Config->Uplinks[Anope::CurrentUplink].port;
+ Anope::Logger.Terminal(_("Successfully connected to uplink #{0} {1}:{2}"), Anope::CurrentUplink + 1, Config->Uplinks[Anope::CurrentUplink].host, Config->Uplinks[Anope::CurrentUplink].port);
IRCD->Handshake();
EventManager::Get()->Dispatch(&Event::ServerConnect::OnServerConnect);
}
void UplinkSocket::OnError(const Anope::string &err)
{
- Anope::string what = !this->flags[SF_CONNECTED] ? "Unable to connect to" : "Lost connection from";
- Log(LOG_TERMINAL) << what << " uplink #" << (Anope::CurrentUplink + 1) << " (" << Config->Uplinks[Anope::CurrentUplink].host << ":" << Config->Uplinks[Anope::CurrentUplink].port << ")" << (!err.empty() ? (": " + err) : "");
+ if (!this->flags[SF_CONNECTED])
+ Anope::Logger.Terminal(_("Unable to connect to uplink #{0} ({1}:{2}): {3}{4}"), Anope::CurrentUplink + 1, Config->Uplinks[Anope::CurrentUplink].host, Config->Uplinks[Anope::CurrentUplink].port, !err.empty() ? (": " + err) : "");
+ else
+ Anope::Logger.Terminal(_("Lost connection from uplink #{0} ({1}:{2}): {3}{4}"), Anope::CurrentUplink + 1, Config->Uplinks[Anope::CurrentUplink].host, Config->Uplinks[Anope::CurrentUplink].port, !err.empty() ? (": " + err) : "");
error |= !err.empty();
}
@@ -177,7 +179,7 @@ void Uplink::SendMessage(IRCMessage &message)
if (s != Me && !s->IsJuped())
{
- Log(LOG_DEBUG) << "Attempted to send \"" << buffer << "\" from " << s->GetName() << " who is not from me?";
+ Anope::Logger.Debug("Attempted to send \"{0}\" from {1} who is not from me?", buffer, s->GetName());
return;
}
}
@@ -187,24 +189,24 @@ void Uplink::SendMessage(IRCMessage &message)
if (u->server != Me && !u->server->IsJuped())
{
- Log(LOG_DEBUG) << "Attempted to send \"" << buffer << "\" from " << u->nick << " who is not from me?";
+ Anope::Logger.Debug("Attempted to send \"{0}\" from {1} who is not from me?", buffer, u->nick);
return;
}
const ServiceBot *bi = source.GetBot();
if (bi != NULL && bi->introduced == false)
{
- Log(LOG_DEBUG) << "Attempted to send \"" << buffer << "\" from " << bi->nick << " when not introduced";
+ Anope::Logger.Debug("Attempted to send \"{0}\" from {1} when not introduced", buffer, bi->nick);
return;
}
}
if (!UplinkSock)
{
- Log(LOG_DEBUG) << "Attempted to send \"" << buffer << "\" with UplinkSock NULL";
+ Anope::Logger.Debug("Attempted to send \"{0}\" when not connected", buffer);
return;
}
UplinkSock->Write(buffer);
- Log(LOG_RAWIO) << "Sent: " << buffer;
+ Anope::Logger.RawIO("Sent: {0}", buffer);
}
diff --git a/src/users.cpp b/src/users.cpp
index a9bb432b5..018f88476 100644
--- a/src/users.cpp
+++ b/src/users.cpp
@@ -40,7 +40,7 @@ int OperCount = 0;
std::list<User *> User::quitting_users;
-User::User(const Anope::string &snick, const Anope::string &sident, const Anope::string &shost, const Anope::string &svhost, const Anope::string &uip, Server *sserver, const Anope::string &srealname, time_t ts, const Anope::string &smodes, const Anope::string &suid, NickServ::Account *account) : ip(uip)
+User::User(const Anope::string &snick, const Anope::string &sident, const Anope::string &shost, const Anope::string &svhost, const Anope::string &uip, Server *sserver, const Anope::string &srealname, time_t ts, const Anope::string &smodes, const Anope::string &suid, NickServ::Account *account) : ip(uip), logger(this)
{
if (snick.empty() || sident.empty() || shost.empty())
throw CoreException("Bad args passed to User::User");
@@ -68,7 +68,7 @@ User::User(const Anope::string &snick, const Anope::string &sident, const Anope:
if (!suid.empty())
UserListByUID[suid] = this;
if (old == UserListByNick.size())
- Log(LOG_DEBUG) << "Duplicate user " << snick << " in user table?";
+ Anope::Logger.Debug("Duplicate user {0} in user table?", snick);
this->Login(account);
this->UpdateHost();
@@ -77,7 +77,7 @@ User::User(const Anope::string &snick, const Anope::string &sident, const Anope:
{
++sserver->users;
if (server->IsSynced())
- Log(this, "connect") << (!vhost.empty() && vhost != host ? "(" + vhost + ") " : "") << "(" << srealname << ") " << (!uip.empty() && uip != host ? "[" + uip + "] " : "") << "connected to the network (" << sserver->GetName() << ")";
+ logger.Category("connect").Log(_("{0} ({1}) ({2}) [{3}] connected to the network ({4})"), this->GetMask(), vhost.empty() ? host : vhost, srealname, uip.empty() ? host : uip, sserver->GetName());
}
bool exempt = false;
@@ -143,7 +143,7 @@ void User::ChangeNick(const Anope::string &newnick, time_t ts)
throw CoreException("User::ChangeNick() got a bad argument");
this->super_admin = false;
- Log(this, "nick") << "(" << this->realname << ") changed nick to " << newnick;
+ logger.Category("nick").Log(_("{0} ({1}) changed nick to {2}"), this->GetMask(), this->realname, newnick);
Anope::string old = this->nick;
this->timestamp = ts;
@@ -196,7 +196,7 @@ void User::SetDisplayedHost(const Anope::string &shost)
this->vhost = shost;
- Log(this, "host") << "changed vhost to " << shost;
+ logger.Category("host").Log(_("{0} changed vhost to {1}"), this->GetMask(), shost);
EventManager::Get()->Dispatch(&Event::SetDisplayedHost::OnSetDisplayedHost, this);
@@ -220,7 +220,7 @@ void User::SetCloakedHost(const Anope::string &newhost)
chost = newhost;
- Log(this, "host") << "changed cloaked host to " << newhost;
+ logger.Category("host").Log(_("{0} changed cloaked host to {1}"), this->GetMask(), newhost);
this->UpdateHost();
}
@@ -242,7 +242,7 @@ void User::SetVIdent(const Anope::string &sident)
{
this->vident = sident;
- Log(this, "ident") << "changed vident to " << sident;
+ logger.Category("ident").Log(_("{0} changed vident to {1}"), this->GetMask(), sident);
this->UpdateHost();
}
@@ -259,7 +259,7 @@ void User::SetIdent(const Anope::string &sident)
{
this->ident = sident;
- Log(this, "ident") << "changed real ident to " << sident;
+ logger.Category("ident").Log(_("{0} changed real ident to {1}"), this->GetMask(), sident);
this->UpdateHost();
}
@@ -292,7 +292,7 @@ void User::SetRealname(const Anope::string &srealname)
if (na && (this->IsIdentified(true) || this->IsRecognized()))
na->SetLastRealname(srealname);
- Log(this, "realname") << "changed realname to " << srealname;
+ logger.Category("realname").Log(_("{0} changed realname to {1}"), this->GetMask(), srealname);
}
User::~User()
@@ -300,7 +300,7 @@ User::~User()
if (this->server != NULL)
{
if (this->server->IsSynced())
- Log(this, "disconnect") << "(" << this->realname << ") disconnected from the network (" << this->server->GetName() << ")";
+ logger.Category("disconnect").Log(_("{0} ({1}) disconnected from the network ({2})"), this->GetMask(), this->realname, this->server->GetName());
--this->server->users;
}
@@ -421,7 +421,7 @@ void User::Login(NickServ::Account *core)
this->UpdateHost();
if (this->server->IsSynced())
- Log(this, "account") << "is now identified as " << this->nc->GetDisplay();
+ logger.Category("account").Log(_("{0} is now identified as {1}"), this->GetMask(), this->nc->GetDisplay());
EventManager::Get()->Dispatch(&Event::UserLogin::OnUserLogin, this);
}
@@ -431,7 +431,7 @@ void User::Logout()
if (!this->nc)
return;
- Log(this, "account") << "is no longer identified as " << this->nc->GetDisplay();
+ logger.Category("account").Log(_("{0} is no longer identified as {1}"), this->GetMask(), this->nc->GetDisplay());
auto it = std::find(this->nc->users.begin(), this->nc->users.end(), this);
if (it != this->nc->users.end())
@@ -687,7 +687,7 @@ void User::SetModesInternal(const MessageSource &source, const char *umodes, ...
va_end(args);
if (this->server && this->server->IsSynced() && Anope::string(buf) != "+")
- Log(this, "mode") << "changes modes to " << buf;
+ logger.Category("mode").Log(_("{0} changes mode to {1}"), this->GetMask(), buf);
spacesepstream sep(buf);
sep.GetToken(modebuf);
@@ -771,11 +771,11 @@ void User::KillInternal(const MessageSource &source, const Anope::string &reason
{
if (this->quit)
{
- Log(LOG_DEBUG) << "Duplicate quit for " << this->nick;
+ Anope::Logger.Debug("Duplicate quit for {0}", this->nick);
return;
}
- Log(this, "killed") << "was killed by " << source.GetName() << " (Reason: " << reason << ")";
+ logger.Category("killed").Log(_("{0} was killed by {1} (Reason: {2})"), this->GetMask(), source.GetName(), reason);
this->Quit(reason);
}
@@ -784,7 +784,7 @@ void User::Quit(const Anope::string &reason)
{
if (this->quit)
{
- Log(LOG_DEBUG) << "Duplicate quit for " << this->nick;
+ Anope::Logger.Debug("Duplicate quit for {0}", this->nick);
return;
}
@@ -799,7 +799,7 @@ bool User::Quitting() const
return this->quit;
}
-Anope::string User::Mask() const
+Anope::string User::WildMask() const
{
Anope::string mask;
const Anope::string &mident = this->GetIdent();
@@ -813,7 +813,7 @@ Anope::string User::Mask() const
sockaddrs addr(mhost);
if (addr.valid() && addr.sa.sa_family == AF_INET)
{
- size_t dot = mhost.find('.');
+ size_t dot = mhost.rfind('.');
mask += mhost.substr(0, dot) + (dot == Anope::string::npos ? "" : ".*");
}
else
diff --git a/src/xline.cpp b/src/xline.cpp
index 7d26461b4..8fa7085c8 100644
--- a/src/xline.cpp
+++ b/src/xline.cpp
@@ -48,7 +48,7 @@ void XLine::Recache()
}
catch (const std::regex_error &ex)
{
- Log(LOG_DEBUG) << ex.what();
+ Anope::Logger.Debug(ex.what());
}
}