summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam <Adam@anope.org>2017-10-22 17:16:32 -0400
committerAdam <Adam@anope.org>2017-10-22 17:16:32 -0400
commit14235cf938f1b93211f2d7538c3d3a39a64341e5 (patch)
treeaf5ebc03c200697baef268a5a99f4073c47b7fdf
parent6d79b0944026c8a8bb28ab47a53d70fb423f5aac (diff)
Store full and masked message in logger for chanserv/log
-rw-r--r--include/event.h4
-rw-r--r--include/logger.h27
-rw-r--r--modules/chanserv/main/chanserv.cpp2
-rw-r--r--modules/operserv/main/operserv.cpp2
-rw-r--r--src/logger.cpp39
5 files changed, 53 insertions, 21 deletions
diff --git a/include/event.h b/include/event.h
index 985eb6ef7..0dc200c7e 100644
--- a/include/event.h
+++ b/include/event.h
@@ -1083,9 +1083,9 @@ namespace Event
using Events::Events;
/** Called when a message is logged
- * @param l The log message
+ * @param logger The logger
*/
- virtual void OnLog(Logger *l) anope_abstract;
+ virtual void OnLog(Logger *logger) anope_abstract;
};
struct CoreExport LogMessage : Events
diff --git a/include/logger.h b/include/logger.h
index 933a753af..64800ccee 100644
--- a/include/logger.h
+++ b/include/logger.h
@@ -108,6 +108,10 @@ class Logger
Anope::string category;
/* Non formatted message */
Anope::string raw_message;
+ /* Message */
+ Anope::string full_message;
+ /* Masked message */
+ Anope::string masked_message;
/* Sources */
User *user = nullptr;
@@ -116,18 +120,18 @@ class Logger
ChanServ::Channel *ci = nullptr;
CommandSource *source = nullptr;
- Anope::string FormatSource() const;
+ Anope::string FormatSource(bool full) const;
Anope::string BuildPrefix() const;
- void LogMessage(const Anope::string &message);
- void InsertVariables(FormatInfo &fi);
+ void LogMessage();
+ void InsertVariables(FormatInfo &fi, bool full);
void CheckOverride();
template<typename... Args>
- Anope::string Format(const Anope::string &message, Args&&... args)
+ Anope::string Format(const Anope::string &message, bool full, Args&&... args)
{
FormatInfo fi(message, sizeof...(Args));
fi.AddArgs(std::forward<Args>(args)...);
- InsertVariables(fi);
+ InsertVariables(fi, full);
fi.Format();
return fi.GetFormat();
}
@@ -164,6 +168,10 @@ class Logger
CommandSource *GetSource() const;
void SetSource(CommandSource *);
+ const Anope::string &GetUnformattedMessage() const;
+ const Anope::string &GetMessage() const;
+ const Anope::string &GetMaskedMessage() const;
+
Logger Category(const Anope::string &c) const;
Logger User(class User *u) const;
Logger Channel(class Channel *c) const;
@@ -179,12 +187,15 @@ class Logger
l.level = lev;
Anope::string translated = Language::Translate(message);
- l.LogMessage(l.Format(translated, std::forward<Args>(args)...));
+ l.full_message = l.Format(translated, true, std::forward<Args>(args)...);
+ l.masked_message = l.Format(translated, false, std::forward<Args>(args)...);
+ l.LogMessage();
}
template<typename... Args> void Command(LogType ltype, CommandSource &csource, ChanServ::Channel *chan, const Anope::string &message, Args&&... args)
{
Logger l = *this;
+ l.raw_message = message;
l.type = ltype;
l.SetSource(&csource);
l.SetCi(chan);
@@ -193,7 +204,9 @@ class Logger
l.CheckOverride();
Anope::string translated = Language::Translate(message);
- l.LogMessage(l.Format(translated, std::forward<Args>(args)...));
+ l.full_message = l.Format(translated, true, std::forward<Args>(args)...);
+ l.masked_message = l.Format(translated, false, std::forward<Args>(args)...);
+ l.LogMessage();
}
template<typename... Args> void Command(LogType ltype, CommandSource &csource, const Anope::string &message, Args&&... args)
diff --git a/modules/chanserv/main/chanserv.cpp b/modules/chanserv/main/chanserv.cpp
index 3c6fe000a..2abd93d71 100644
--- a/modules/chanserv/main/chanserv.cpp
+++ b/modules/chanserv/main/chanserv.cpp
@@ -406,7 +406,7 @@ class ChanServCore : public Module
}
}
- void OnLog(Logger *l) override
+ void OnLog(Logger *logger) override
{
#warning ""
#if 0
diff --git a/modules/operserv/main/operserv.cpp b/modules/operserv/main/operserv.cpp
index b439653f9..2dbd0d260 100644
--- a/modules/operserv/main/operserv.cpp
+++ b/modules/operserv/main/operserv.cpp
@@ -320,7 +320,7 @@ class OperServCore : public Module
{
}
- void OnLog(Logger *l) override
+ void OnLog(Logger *logger) override
{
#warning ""
#if 0
diff --git a/src/logger.cpp b/src/logger.cpp
index adb880065..78455e260 100644
--- a/src/logger.cpp
+++ b/src/logger.cpp
@@ -285,7 +285,7 @@ void LogInfo::ProcessMessage(const Logger *l, const Anope::string &message)
}
}
-void Logger::InsertVariables(FormatInfo &fi)
+void Logger::InsertVariables(FormatInfo &fi, bool full)
{
if (user != nullptr)
fi.Add("user"_kw = user->GetMask());
@@ -295,7 +295,7 @@ void Logger::InsertVariables(FormatInfo &fi)
else if (channel != nullptr)
fi.Add("channel"_kw = channel->GetName());
- fi.Add("source"_kw = this->FormatSource());
+ fi.Add("source"_kw = this->FormatSource(full));
if (source != nullptr && !source->GetCommand().empty())
fi.Add("command"_kw = source->GetCommand());
@@ -309,13 +309,17 @@ void Logger::CheckOverride()
type = LogType::OVERRIDE;
}
-Anope::string Logger::FormatSource() const
+Anope::string Logger::FormatSource(bool full) const
{
if (user)
+ {
+ const Anope::string &umask = full ? user->GetMask() : user->GetDisplayedMask();
+
if (account)
- return user->GetMask() + " (" + account->GetDisplay() + ")";
+ return umask + " (" + account->GetDisplay() + ")";
else
- return user->GetMask();
+ return umask;
+ }
else if (account)
return account->GetDisplay();
else if (source)
@@ -348,14 +352,14 @@ Anope::string Logger::BuildPrefix() const
return "";
}
-void Logger::LogMessage(const Anope::string &message)
+void Logger::LogMessage()
{
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;
+ std::cout << GetTimeStamp() << " Debug: " << this->BuildPrefix() << full_message << std::endl;
else if (Anope::NoFork && level <= LogLevel::TERMINAL)
- std::cout << GetTimeStamp() << " " << this->BuildPrefix() << message << std::endl;
+ std::cout << GetTimeStamp() << " " << this->BuildPrefix() << full_message << std::endl;
else if (level == LogLevel::TERMINAL)
- std::cout << this->BuildPrefix() << message << std::endl;
+ std::cout << this->BuildPrefix() << full_message << std::endl;
if (level <= LogLevel::NORMAL)
{
@@ -367,7 +371,7 @@ void Logger::LogMessage(const Anope::string &message)
if (Config != nullptr)
for (LogInfo &info : Config->LogInfos)
if (info.HasType(this->type, this->level, this->category))
- info.ProcessMessage(this, message);
+ info.ProcessMessage(this, full_message);
}
LogType Logger::GetType() const
@@ -456,6 +460,21 @@ void Logger::SetSource(CommandSource *s)
}
}
+const Anope::string &Logger::GetUnformattedMessage() const
+{
+ return raw_message;
+}
+
+const Anope::string &Logger::GetMessage() const
+{
+ return full_message;
+}
+
+const Anope::string &Logger::GetMaskedMessage() const
+{
+ return masked_message;
+}
+
Logger Logger::Category(const Anope::string &c) const
{
Logger l = *this;