summaryrefslogtreecommitdiff
path: root/src/logger.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/logger.cpp')
-rw-r--r--src/logger.cpp73
1 files changed, 46 insertions, 27 deletions
diff --git a/src/logger.cpp b/src/logger.cpp
index c681e42fa..0d379e568 100644
--- a/src/logger.cpp
+++ b/src/logger.cpp
@@ -1,12 +1,20 @@
-/* Logging routines.
+/*
+ * Anope IRC Services
*
- * (C) 2003-2016 Anope Team
- * Contact us at team@anope.org
+ * Copyright (C) 2010-2016 Anope Team <team@anope.org>
*
- * Please read COPYING and README for further details.
+ * This file is part of Anope. Anope is free software; you can
+ * redistribute it and/or modify it under the terms of the GNU
+ * General Public License as published by the Free Software
+ * Foundation, version 2.
*
- * Based on the original code of Epona by Lara.
- * Based on the original code of Services by Andy Church.
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see see <http://www.gnu.org/licenses/>.
*/
#include "services.h"
@@ -20,6 +28,9 @@
#include "servers.h"
#include "uplink.h"
#include "protocol.h"
+#include "event.h"
+#include "modules/nickserv.h"
+#include "modules/chanserv.h"
#ifndef _WIN32
#include <sys/time.h>
@@ -74,23 +85,23 @@ const Anope::string &LogFile::GetName() const
return this->filename;
}
-Log::Log(LogType t, const Anope::string &cat, BotInfo *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, 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, ChannelInfo *_ci) : u(src.GetUser()), nc(src.nc), c(_c), source(&src), chan(NULL), ci(_ci), s(NULL), m(NULL), type(t)
+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->name.find('/');
+ size_t sl = c->GetName().find('/');
this->bi = NULL;
if (sl != Anope::string::npos)
- this->bi = BotInfo::Find(c->name.substr(0, sl), true);
- this->category = c->name;
+ 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)
@@ -99,23 +110,23 @@ Log::Log(User *_u, Channel *ch, const Anope::string &cat) : bi(NULL), u(_u), nc(
throw CoreException("Invalid pointers passed to Log::Log");
}
-Log::Log(User *_u, const Anope::string &cat, BotInfo *_bi) : bi(_bi), u(_u), nc(NULL), c(NULL), source(NULL), chan(NULL), ci(NULL), s(NULL), m(NULL), type(LOG_USER), category(cat)
+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, BotInfo *_bi) : bi(_bi), u(NULL), nc(NULL), c(NULL), source(NULL), chan(NULL), ci(NULL), s(serv), m(NULL), type(LOG_SERVER), category(cat)
+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(BotInfo *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(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, BotInfo *_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(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)
{
}
@@ -128,8 +139,16 @@ Log::~Log()
else if (this->type == LOG_TERMINAL)
std::cout << this->BuildPrefix() << this->buf.str() << std::endl;
- FOREACH_MOD(OnLog, (this));
-
+ /* 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))
@@ -140,19 +159,19 @@ Anope::string Log::FormatSource() const
{
if (u)
if (nc)
- return this->u->GetMask() + " (" + this->nc->display + ")";
+ return this->u->GetMask() + " (" + this->nc->GetDisplay() + ")";
else
return this->u->GetMask();
else if (nc)
- return nc->display;
+ return nc->GetDisplay();
return "";
}
Anope::string Log::FormatCommand() const
{
- Anope::string buffer = FormatSource() + " used " + (source != NULL && !source->command.empty() ? source->command : this->c->name) + " ";
+ Anope::string buffer = FormatSource() + " used " + (source != NULL && !source->command.empty() ? source->command : this->c->GetName()) + " ";
if (this->ci)
- buffer += "on " + this->ci->name + " ";
+ buffer += "on " + this->ci->GetName() + " ";
return buffer;
}
@@ -329,9 +348,9 @@ void LogInfo::ProcessMessage(const Log *l)
log = true;
else if (l->u && src == l->u->nick)
log = true;
- else if (l->nc && src == l->nc->display)
+ else if (l->nc && src == l->nc->GetDisplay())
log = true;
- else if (l->ci && src == l->ci->name)
+ else if (l->ci && src == l->ci->GetName())
log = true;
else if (l->m && src == l->m->name)
log = true;
@@ -344,7 +363,7 @@ void LogInfo::ProcessMessage(const Log *l)
const Anope::string &buffer = l->BuildPrefix() + l->buf.str();
- FOREACH_MOD(OnLogMessage, (this, l, buffer));
+ EventManager::Get()->Dispatch(&Event::LogMessage::OnLogMessage, this, l, buffer);
for (unsigned i = 0; i < this->targets.size(); ++i)
{
@@ -358,7 +377,7 @@ void LogInfo::ProcessMessage(const Log *l)
if (!c)
continue;
- BotInfo *bi = l->bi;
+ User *bi = l->bi;
if (!bi)
bi = this->bot;
if (!bi)
@@ -375,7 +394,7 @@ void LogInfo::ProcessMessage(const Log *l)
}
}
}
-
+
tm *tm = localtime(&Anope::CurTime);
if (tm->tm_mday != this->last_day)
{