1
0
mirror of https://github.com/anope/anope.git synced 2026-07-03 05:13:14 +02:00

Add a module log type

This commit is contained in:
Adam
2012-10-27 08:12:04 -04:00
parent bb5f4555dc
commit d6e1b92059
21 changed files with 75 additions and 59 deletions
+4
View File
@@ -24,6 +24,7 @@ enum LogType
LOG_SERVER,
LOG_CHANNEL,
LOG_USER,
LOG_MODULE,
LOG_NORMAL,
LOG_TERMINAL,
LOG_RAWIO,
@@ -56,6 +57,7 @@ class CoreExport Log
Channel *chan;
const ChannelInfo *ci;
Server *s;
Module *m;
LogType Type;
Anope::string Category;
std::list<Anope::string> Sources;
@@ -78,6 +80,8 @@ class CoreExport Log
explicit Log(const BotInfo *b, const Anope::string &category = "");
Log(Module *m, const Anope::string &category = "");
~Log();
Anope::string BuildPrefix() const;
+1 -1
View File
@@ -44,7 +44,7 @@ class CommandMSRSend : public Command
source.Reply(ACCESS_DENIED);
else if (Config->MSMemoReceipt > 2 || Config->MSMemoReceipt == 0)
{
Log() << "MSMemoReceipt is set misconfigured to " << Config->MSMemoReceipt;
Log(this->owner) << "MSMemoReceipt is set misconfigured to " << Config->MSMemoReceipt;
source.Reply(_("Sorry, RSEND has been disabled on this network."));
}
else
+1 -1
View File
@@ -307,7 +307,7 @@ class CommandNSResend : public Command
Log(LOG_COMMAND, source, this) << "to resend registration verification code";
}
else
Log() << "Unable to resend registration verification code for " << source.GetNick();
Log(this->owner) << "Unable to resend registration verification code for " << source.GetNick();
}
return;
+3 -3
View File
@@ -282,7 +282,7 @@ class OSDefcon : public Module
{
if (cm->Type == MODE_STATUS || cm->Type == MODE_LIST || !cm->CanSet(NULL))
{
Log() << "DefConChanModes mode character '" << mode << "' cannot be locked";
Log(this) << "DefConChanModes mode character '" << mode << "' cannot be locked";
continue;
}
else if (add)
@@ -296,7 +296,7 @@ class OSDefcon : public Module
if (!ss.GetToken(param))
{
Log() << "DefConChanModes mode character '" << mode << "' has no parameter while one is expected";
Log(this) << "DefConChanModes mode character '" << mode << "' has no parameter while one is expected";
continue;
}
@@ -321,7 +321,7 @@ class OSDefcon : public Module
{
DConfig.DefConModesOn.UnsetFlag(CMODE_REDIRECT);
Log() << "DefConChanModes must lock mode +l as well to lock mode +L";
Log(this) << "DefConChanModes must lock mode +l as well to lock mode +L";
}
}
+8 -8
View File
@@ -430,7 +430,7 @@ class ModuleDNS : public Module
if (dns && !dns->Pooled() && !dns->GetIPs().empty() && dns->GetLimit() < s->Users)
{
dns->Pool(true);
Log() << "Pooling server " << s->GetName();
Log(this) << "Pooling server " << s->GetName();
}
}
}
@@ -442,7 +442,7 @@ class ModuleDNS : public Module
if (dns && dns->Pooled())
{
dns->Pool(false);
Log() << "Depooling delinked server " << s->GetName();
Log(this) << "Depooling delinked server " << s->GetName();
}
}
@@ -454,7 +454,7 @@ class ModuleDNS : public Module
/* Check for user limit reached */
if (s && s->GetLimit() && s->Pooled() && u->server->Users >= s->GetLimit())
{
Log() << "Depooling full server " << s->GetName() << ": " << u->server->Users << " users";
Log(this) << "Depooling full server " << s->GetName() << ": " << u->server->Users << " users";
s->Pool(false);
}
}
@@ -471,7 +471,7 @@ class ModuleDNS : public Module
/* Check for dropping under userlimit */
if (s->GetLimit() && !s->Pooled() && s->GetLimit() > u->server->Users)
{
Log() << "Pooling server " << s->GetName();
Log(this) << "Pooling server " << s->GetName();
s->Pool(true);
}
@@ -489,7 +489,7 @@ class ModuleDNS : public Module
/* Check for very fast user drops */
if (diff <= this->user_drop_time)
{
Log() << "Depooling server " << s->GetName() << ": dropped " << this->user_drop_mark << " users in " << diff << " seconds";
Log(this) << "Depooling server " << s->GetName() << ": dropped " << this->user_drop_mark << " users in " << diff << " seconds";
s->repool = Anope::CurTime + this->user_drop_readd_time;
s->Pool(false);
}
@@ -498,7 +498,7 @@ class ModuleDNS : public Module
{
s->Pool(true);
s->repool = 0;
Log() << "Pooling server " << s->GetName();
Log(this) << "Pooling server " << s->GetName();
}
}
}
@@ -540,7 +540,7 @@ class ModuleDNS : public Module
if (last_warn + 60 < Anope::CurTime)
{
last_warn = Anope::CurTime;
Log() << "os_dns: Warning! There are no pooled servers!";
Log(this) << "os_dns: Warning! There are no pooled servers!";
}
/* Something messed up, just return them all and hope one is available */
@@ -564,7 +564,7 @@ class ModuleDNS : public Module
if (packet->answers.empty())
{
Log() << "os_dns: Error! There are no servers with any IPs. At all.";
Log(this) << "os_dns: Error! There are no servers with any IPs. At all.";
/* Send back an empty answer anyway */
}
}
+1 -1
View File
@@ -141,7 +141,7 @@ class CommandOSModUnLoad : public Command
return;
}
Log() << "Trying to unload module [" << mname << "]";
Log(this->owner) << "Trying to unload module [" << mname << "]";
ModuleReturn status = ModuleManager::UnloadModule(m, source.GetUser());
+1 -1
View File
@@ -36,7 +36,7 @@ class CommandOSReload : public Command
catch (const ConfigException &ex)
{
Config = old_config;
Log() << "Error reloading configuration file: " << ex.GetReason();
Log(this->owner) << "Error reloading configuration file: " << ex.GetReason();
source.Reply(_("Error reloading configuration file: ") + ex.GetReason());
}
+1 -1
View File
@@ -689,7 +689,7 @@ class OSSession : public Module
if (!session)
{
if (debug)
Log() << "session: Tried to delete non-existant session: " << u->host;
Log(this) << "Tried to delete non-existant session: " << u->host;
return;
}
+4 -4
View File
@@ -55,7 +55,7 @@ class DBFlatFile : public Module
Log(LOG_DEBUG) << "db_flatfile: Attemping to rename " << DatabaseFile << " to " << newname;
if (rename(DatabaseFile.c_str(), newname.c_str()))
{
Log() << "Unable to back up database!";
Log(this) << "Unable to back up database!";
if (!Config->NoBackupOkay)
quitting = true;
@@ -88,7 +88,7 @@ class DBFlatFile : public Module
if (!databases[NULL]->is_open())
{
delete databases[NULL];
Log() << "Unable to open " << DatabaseFile << " for reading!";
Log(this) << "Unable to open " << DatabaseFile << " for reading!";
return EVENT_CONTINUE;
}
@@ -168,7 +168,7 @@ class DBFlatFile : public Module
if (!databases[NULL]->is_open())
{
delete databases[NULL];
Log() << "Unable to open " << DatabaseFile << " for writing";
Log(this) << "Unable to open " << DatabaseFile << " for writing";
if (IsFile(tmp_db))
rename(tmp_db.c_str(), DatabaseFile.c_str());
return EVENT_CONTINUE;
@@ -200,7 +200,7 @@ class DBFlatFile : public Module
if (databases[NULL]->good() == false)
{
Log() << "Unable to write database";
Log(this) << "Unable to write database";
databases[NULL]->close();
if (!Config->NoBackupOkay)
quitting = true;
+3 -3
View File
@@ -69,7 +69,7 @@ class DBSQL : public Module, public Pipe
if (last_warn + 300 < Anope::CurTime)
{
last_warn = Anope::CurTime;
Log() << "db_sql: Unable to execute query, is SQL configured correctly?";
Log(this) << "db_sql: Unable to execute query, is SQL configured correctly?";
}
}
else if (!quitting)
@@ -146,7 +146,7 @@ class DBSQL : public Module, public Pipe
{
if (!this->sql)
{
Log() << "db_sql: Unable to load databases, is SQL configured correctly?";
Log(this) << "Unable to load databases, is SQL configured correctly?";
return EVENT_CONTINUE;
}
@@ -174,7 +174,7 @@ class DBSQL : public Module, public Pipe
}
catch (const ConvertException &)
{
Log() << "db_sql: Unable to convert id for object #" << j << " of type " << sb->GetName();
Log(this) << "Unable to convert id for object #" << j << " of type " << sb->GetName();
}
}
}
+1 -1
View File
@@ -34,7 +34,7 @@ class BSAutoAssign : public Module
BotInfo *bi = findbot(this->bot);
if (bi == NULL)
{
Log() << "bs_autoassign is configured to assign bot " << this->bot << ", but it does not exist?";
Log(this) << "bs_autoassign is configured to assign bot " << this->bot << ", but it does not exist?";
return;
}
+1 -1
View File
@@ -363,7 +363,7 @@ class MChanstats : public Module
if (sql)
this->CheckTables();
else
Log() << "Chanstats: no database connection to " << engine;
Log(this) << "no database connection to " << engine;
}
void OnTopicUpdated(Channel *c, const Anope::string &user, const Anope::string &topic) anope_override
{
+1 -1
View File
@@ -163,7 +163,7 @@ class ModuleDNSBL : public Module
}
catch (const SocketException &ex)
{
Log() << "m_dnsbl: " << ex.GetReason();
Log(this) << ex.GetReason();
}
}
}
+10 -10
View File
@@ -75,7 +75,7 @@ class IdentifyInterface : public LDAPInterface
}
catch (const LDAPException &ex)
{
Log() << "m_ldap_authentication: Error binding after search: " << ex.GetReason();
Log(this->owner) << "m_ldap_authentication: Error binding after search: " << ex.GetReason();
}
}
break;
@@ -95,7 +95,7 @@ class IdentifyInterface : public LDAPInterface
}
catch (const LDAPException &ex)
{
Log() << "m_ldap_authentication: Unable to search for " << sf << ": " << ex.GetReason();
Log(this->owner) << "m_ldap_authentication: Unable to search for " << sf << ": " << ex.GetReason();
}
}
else
@@ -172,19 +172,19 @@ class OnIdentifyInterface : public LDAPInterface
BotInfo *bi = findbot(Config->NickServ);
if (bi)
u->SendMessage(bi, _("Your email has been updated to \002%s\002"), email.c_str());
Log() << "m_ldap_authentication: Updated email address for " << u->nick << " (" << u->Account()->display << ") to " << email;
Log(this->owner) << "m_ldap_authentication: Updated email address for " << u->nick << " (" << u->Account()->display << ") to " << email;
}
}
catch (const LDAPException &ex)
{
Log() << "m_ldap_authentication: " << ex.GetReason();
Log(this->owner) << "m_ldap_authentication: " << ex.GetReason();
}
}
void OnError(const LDAPResult &r) anope_override
{
this->requests.erase(r.id);
Log() << "m_ldap_authentication: " << r.error;
Log(this->owner) << "m_ldap_authentication: " << r.error;
}
};
@@ -195,12 +195,12 @@ class OnRegisterInterface : public LDAPInterface
void OnResult(const LDAPResult &r) anope_override
{
Log() << "m_ldap_authentication: Successfully added newly created account to LDAP";
Log(this->owner) << "m_ldap_authentication: Successfully added newly created account to LDAP";
}
void OnError(const LDAPResult &r) anope_override
{
Log() << "m_ldap_authentication: Error adding newly created account to LDAP: " << r.getError();
Log(this->owner) << "m_ldap_authentication: Error adding newly created account to LDAP: " << r.getError();
}
};
@@ -268,7 +268,7 @@ class NSIdentifyLDAP : public Module
catch (const LDAPException &ex)
{
delete ii;
Log() << "m_ldap_authentication: " << ex.GetReason();
Log(this) << ex.GetReason();
}
}
@@ -288,7 +288,7 @@ class NSIdentifyLDAP : public Module
}
catch (const LDAPException &ex)
{
Log() << "m_ldap_authentication: " << ex.GetReason();
Log(this) << ex.GetReason();
}
}
@@ -325,7 +325,7 @@ class NSIdentifyLDAP : public Module
}
catch (const LDAPException &ex)
{
Log() << "m_ldap_authentication: " << ex.GetReason();
Log(this) << ex.GetReason();
}
}
};
+3 -3
View File
@@ -50,7 +50,7 @@ class IdentifyInterface : public LDAPInterface
o = new Oper(u->nick, ot);
my_opers.insert(o);
nc->o = o;
Log() << "m_ldap_oper: Tied " << u->nick << " (" << nc->display << ") to opertype " << ot->GetName();
Log(this->owner) << "m_ldap_oper: Tied " << u->nick << " (" << nc->display << ") to opertype " << ot->GetName();
}
}
catch (const LDAPException &ex)
@@ -64,7 +64,7 @@ class IdentifyInterface : public LDAPInterface
}
nc->o = NULL;
Log() << "m_ldap_oper: Removed services operator from " << u->nick << " (" << nc->display << ")";
Log() << "Removed services operator from " << u->nick << " (" << nc->display << ")";
}
}
}
@@ -127,7 +127,7 @@ class LDAPOper : public Module
}
catch (const LDAPException &ex)
{
Log() << "m_ldapoper: " << ex.GetReason();
Log() << ex.GetReason();
}
}
+1 -1
View File
@@ -53,7 +53,7 @@ class MySQLResult : public SQLResult
{
unsigned num_fields = res ? mysql_num_fields(res) : 0;
/* It is not thread safe to log anything here using Log() now :( */
/* It is not thread safe to log anything here using Log(this->owner) now :( */
if (!num_fields)
return;
+2 -2
View File
@@ -65,7 +65,7 @@ class SQLAuthenticationResult : public SQLInterface
void OnError(const SQLResult &r) anope_override
{
Log() << "m_sql_authentication: Error executing query " << r.GetQuery().query << ": " << r.GetError();
Log(this->owner) << "m_sql_authentication: Error executing query " << r.GetQuery().query << ": " << r.GetError();
delete this;
}
};
@@ -119,7 +119,7 @@ class ModuleSQLAuthentication : public Module
{
if (!this->SQL)
{
Log() << "m_sql_authentication: Unable to find SQL engine";
Log(this) << "Unable to find SQL engine";
return;
}
+5 -5
View File
@@ -50,7 +50,7 @@ class SQLOperResult : public SQLInterface
Config->Opers.erase(it);
delete user->Account()->o;
user->Account()->o = NULL;
Log() << "m_sql_oper: Removed services operator from " << user->nick << " (" << user->Account()->display << ")";
Log(this->owner) << "m_sql_oper: Removed services operator from " << user->nick << " (" << user->Account()->display << ")";
user->RemoveMode(findbot(Config->OperServ), UMODE_OPER); // Probably not set, just incase
}
return;
@@ -59,13 +59,13 @@ class SQLOperResult : public SQLInterface
OperType *ot = OperType::Find(opertype);
if (ot == NULL)
{
Log() << "m_sql_oper: Oper " << user->nick << " has type " << opertype << ", but this opertype does not exist?";
Log(this->owner) << "m_sql_oper: Oper " << user->nick << " has type " << opertype << ", but this opertype does not exist?";
return;
}
if (!user->Account()->o || user->Account()->o->ot != ot)
{
Log() << "m_sql_oper: Tieing oper " << user->nick << " to type " << opertype;
Log(this->owner) << "m_sql_oper: Tieing oper " << user->nick << " to type " << opertype;
user->Account()->o = new Oper(user->Account()->display, ot);
Config->Opers.push_back(user->Account()->o);
}
@@ -82,7 +82,7 @@ class SQLOperResult : public SQLInterface
void OnError(const SQLResult &r) anope_override
{
SQLOperResultDeleter d(this);
Log() << "m_sql_oper: Error executing query " << r.GetQuery().query << ": " << r.GetError();
Log(this->owner) << "m_sql_oper: Error executing query " << r.GetQuery().query << ": " << r.GetError();
}
};
@@ -118,7 +118,7 @@ class ModuleSQLOper : public Module
{
if (!this->SQL)
{
Log() << "m_sql_oper: Unable to find SQL engine";
Log() << "Unable to find SQL engine";
return;
}
+2 -2
View File
@@ -122,7 +122,7 @@ class SSLModule : public Module
Log(LOG_DEBUG) << "m_ssl: Successfully loaded certificate " << this->certfile;
}
else
Log() << "m_ssl: Unable to open certificate " << this->certfile;
Log() << "Unable to open certificate " << this->certfile;
if (IsFile(this->keyfile.c_str()))
{
@@ -144,7 +144,7 @@ class SSLModule : public Module
throw ModuleException("Error loading private key " + this->keyfile + " - file not found");
}
else
Log() << "m_ssl: Unable to open private key " << this->keyfile;
Log() << "Unable to open private key " << this->keyfile;
}
SSL_CTX_set_mode(client_ctx, SSL_MODE_ENABLE_PARTIAL_WRITE | SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER);
+2 -2
View File
@@ -286,7 +286,7 @@ class ModuleXMLRPC : public Module
if (ssl && !sslref)
{
Log() << "m_xmlrpc: Could not enable SSL, is m_ssl loaded?";
Log(this) << "Could not enable SSL, is m_ssl loaded?";
ssl = false;
}
@@ -298,7 +298,7 @@ class ModuleXMLRPC : public Module
}
catch (const SocketException &ex)
{
Log() << "m_xmlrpc " << ex.GetReason();
Log(this) << ex.GetReason();
}
}
}
+20 -8
View File
@@ -79,7 +79,7 @@ Log::Log(LogType type, const Anope::string &category, const BotInfo *b) : bi(b),
this->Sources.push_back(bi->nick);
}
Log::Log(LogType type, CommandSource &source, Command *_c, const ChannelInfo *_ci) : nick(source.GetNick()), u(source.GetUser()), nc(source.nc), c(_c), chan(NULL), ci(_ci), s(NULL), Type(type)
Log::Log(LogType type, CommandSource &source, Command *_c, const ChannelInfo *_ci) : nick(source.GetNick()), u(source.GetUser()), nc(source.nc), c(_c), chan(NULL), ci(_ci), s(NULL), m(NULL), Type(type)
{
if (!c)
throw CoreException("Invalid pointers passed to Log::Log");
@@ -103,7 +103,7 @@ Log::Log(LogType type, CommandSource &source, Command *_c, const ChannelInfo *_c
this->Sources.push_back(ci->name);
}
Log::Log(const User *_u, Channel *ch, const Anope::string &category) : bi(NULL), u(_u), nc(NULL), c(NULL), chan(ch), ci(chan ? *chan->ci : NULL), s(NULL), Type(LOG_CHANNEL)
Log::Log(const User *_u, Channel *ch, const Anope::string &category) : bi(NULL), u(_u), nc(NULL), c(NULL), chan(ch), ci(chan ? *chan->ci : NULL), s(NULL), m(NULL), Type(LOG_CHANNEL)
{
if (!chan)
throw CoreException("Invalid pointers passed to Log::Log");
@@ -118,7 +118,7 @@ Log::Log(const User *_u, Channel *ch, const Anope::string &category) : bi(NULL),
this->Sources.push_back(chan->name);
}
Log::Log(const User *_u, const Anope::string &category, const BotInfo *_bi) : bi(_bi), u(_u), nc(NULL), c(NULL), chan(NULL), ci(NULL), s(NULL), Type(LOG_USER), Category(category)
Log::Log(const User *_u, const Anope::string &category, const BotInfo *_bi) : bi(_bi), u(_u), nc(NULL), c(NULL), chan(NULL), ci(NULL), s(NULL), m(NULL), Type(LOG_USER), Category(category)
{
if (!u)
throw CoreException("Invalid pointers passed to Log::Log");
@@ -130,7 +130,7 @@ Log::Log(const User *_u, const Anope::string &category, const BotInfo *_bi) : bi
this->Sources.push_back(u->nick);
}
Log::Log(Server *serv, const Anope::string &category, const BotInfo *_bi) : bi(_bi), u(NULL), nc(NULL), c(NULL), chan(NULL), ci(NULL), s(serv), Type(LOG_SERVER), Category(category)
Log::Log(Server *serv, const Anope::string &category, const BotInfo *_bi) : bi(_bi), u(NULL), nc(NULL), c(NULL), chan(NULL), ci(NULL), s(serv), m(NULL), Type(LOG_SERVER), Category(category)
{
if (!s)
throw CoreException("Invalid pointer passed to Log::Log");
@@ -144,7 +144,7 @@ Log::Log(Server *serv, const Anope::string &category, const BotInfo *_bi) : bi(_
this->Sources.push_back(s->GetName());
}
Log::Log(const BotInfo *b, const Anope::string &category) : bi(b), u(NULL), nc(NULL), c(NULL), chan(NULL), ci(NULL), s(NULL), Type(LOG_NORMAL), Category(category)
Log::Log(const BotInfo *b, const Anope::string &category) : bi(b), u(NULL), nc(NULL), c(NULL), chan(NULL), ci(NULL), s(NULL), m(NULL), Type(LOG_NORMAL), Category(category)
{
if (!this->bi && Config)
this->bi = findbot(Config->Global);
@@ -152,6 +152,12 @@ Log::Log(const BotInfo *b, const Anope::string &category) : bi(b), u(NULL), nc(N
this->Sources.push_back(bi->nick);
}
Log::Log(Module *mod, const Anope::string &category) : bi(NULL), u(NULL), nc(NULL), c(NULL), chan(NULL), ci(NULL), s(NULL), m(mod), Type(LOG_MODULE), Category(category)
{
if (m)
this->Sources.push_back(m->name);
}
Log::~Log()
{
if (nofork && debug && this->Type >= LOG_NORMAL && this->Type <= LOG_DEBUG + debug - 1)
@@ -244,6 +250,12 @@ Anope::string Log::BuildPrefix() const
buffer += "SERVER: " + this->s->GetName() + " (" + this->s->GetDescription() + ") ";
break;
}
case LOG_MODULE:
{
if (this->m)
buffer += this->m->name.upper() + ": ";
break;
}
default:
break;
}
@@ -305,16 +317,16 @@ bool LogInfo::HasType(LogType ltype, const Anope::string &type) const
case LOG_USER:
list = &this->Users;
break;
case LOG_NORMAL:
list = &this->Normal;
break;
case LOG_TERMINAL:
return true;
case LOG_RAWIO:
return debug ? true : this->RawIO;
case LOG_DEBUG:
return debug ? true : this->Debug;
case LOG_MODULE:
case LOG_NORMAL:
default:
list = &this->Normal;
break;
}