aboutsummaryrefslogtreecommitdiff
path: root/src/common/Logging/Log.cpp
diff options
context:
space:
mode:
authorShauren <shauren.trinity@gmail.com>2025-06-23 11:38:34 +0200
committerShauren <shauren.trinity@gmail.com>2025-06-23 11:38:34 +0200
commitd62b412c925ffa348b9586ebbf43adc15cb12462 (patch)
treebb9005ef1135e73821b3f1ad4db493e0646b8b8b /src/common/Logging/Log.cpp
parentbe448017289c3c8df2d6dc44fe93b16b91b02daf (diff)
Core/Misc: Remove StringFormat exception handling code from the header
Diffstat (limited to 'src/common/Logging/Log.cpp')
-rw-r--r--src/common/Logging/Log.cpp20
1 files changed, 9 insertions, 11 deletions
diff --git a/src/common/Logging/Log.cpp b/src/common/Logging/Log.cpp
index 643f0c8483c..4514fbabd1a 100644
--- a/src/common/Logging/Log.cpp
+++ b/src/common/Logging/Log.cpp
@@ -27,9 +27,8 @@
#include "StringConvert.h"
#include "Util.h"
-Log::Log() : AppenderId(0), lowestLogLevel(LOG_LEVEL_FATAL), _ioContext(nullptr), _strand(nullptr)
+Log::Log() : AppenderId(0), lowestLogLevel(LOG_LEVEL_FATAL), m_logsTimestamp('_' + GetTimestampStr()), _ioContext(nullptr), _strand(nullptr)
{
- m_logsTimestamp = "_" + GetTimestampStr();
RegisterAppender<AppenderConsole>();
RegisterAppender<AppenderFile>();
}
@@ -214,12 +213,11 @@ void Log::ReadLoggersFromConfig()
void Log::RegisterAppender(uint8 index, AppenderCreatorFn appenderCreateFn)
{
- auto itr = appenderFactory.find(index);
- ASSERT(itr == appenderFactory.end());
- appenderFactory[index] = appenderCreateFn;
+ [[maybe_unused]] bool isNewAppender = appenderFactory.try_emplace(index, appenderCreateFn).second;
+ ASSERT(isNewAppender);
}
-void Log::OutMessageImpl(Logger const* logger, std::string_view filter, LogLevel level, Trinity::FormatStringView messageFormat, Trinity::FormatArgs messageFormatArgs) const
+void Log::OutMessageImpl(Logger const* logger, std::string_view filter, LogLevel level, Trinity::FormatStringView messageFormat, Trinity::FormatArgs messageFormatArgs) const noexcept
{
if (_ioContext)
Trinity::Asio::post(*_strand, LogOperation(logger, new LogMessage(level, filter, Trinity::StringVFormat(messageFormat, messageFormatArgs))));
@@ -230,7 +228,7 @@ void Log::OutMessageImpl(Logger const* logger, std::string_view filter, LogLevel
}
}
-void Log::OutCommandImpl(uint32 account, Trinity::FormatStringView messageFormat, Trinity::FormatArgs messageFormatArgs) const
+void Log::OutCommandImpl(uint32 account, Trinity::FormatStringView messageFormat, Trinity::FormatArgs messageFormatArgs) const noexcept
{
Logger const* logger = GetLoggerByType("commands.gm");
@@ -298,7 +296,7 @@ bool Log::SetLogLevel(std::string const& name, int32 newLeveli, bool isLogger /*
return true;
}
-void Log::OutCharDump(std::string const& str, uint32 accountId, uint64 guid, std::string const& name) const
+void Log::OutCharDump(std::string const& str, uint32 accountId, uint64 guid, std::string const& name) const noexcept
{
if (!ShouldLog("entities.player.dump", LOG_LEVEL_INFO))
return;
@@ -329,7 +327,7 @@ void Log::Close()
appenders.clear();
}
-bool Log::ShouldLog(std::string_view type, LogLevel level) const
+bool Log::ShouldLog(std::string_view type, LogLevel level) const noexcept
{
// TODO: Use cache to store "Type.sub1.sub2": "Type" equivalence, should
// Speed up in cases where requesting "Type.sub1.sub2" but only configured
@@ -347,7 +345,7 @@ bool Log::ShouldLog(std::string_view type, LogLevel level) const
return logLevel != LOG_LEVEL_DISABLED && logLevel <= level;
}
-Logger const* Log::GetEnabledLogger(std::string_view type, LogLevel level) const
+Logger const* Log::GetEnabledLogger(std::string_view type, LogLevel level) const noexcept
{
// Don't even look for a logger if the LogLevel is lower than lowest log levels across all loggers
if (level < lowestLogLevel)
@@ -361,7 +359,7 @@ Logger const* Log::GetEnabledLogger(std::string_view type, LogLevel level) const
return logLevel != LOG_LEVEL_DISABLED && logLevel <= level ? logger : nullptr;
}
-Log* Log::instance()
+Log* Log::instance() noexcept
{
static Log instance;
return &instance;