Core/Misc: Remove StringFormat exception handling code from the header

This commit is contained in:
Shauren
2025-06-23 11:38:34 +02:00
parent be44801728
commit d62b412c92
6 changed files with 80 additions and 75 deletions

View File

@@ -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;