From aaa6e73c8ca6d60e943cb964605536eb78219db2 Mon Sep 17 00:00:00 2001 From: Shauren Date: Tue, 15 Aug 2023 20:10:04 +0200 Subject: Core/Logging: Switch from fmt::sprintf to fmt::format (c++20 standard compatible api) (cherry picked from commit d791afae1dfcfaf592326f787755ca32d629e4d3) --- src/common/Logging/Log.h | 44 ++++++++++++-------------------------------- 1 file changed, 12 insertions(+), 32 deletions(-) (limited to 'src/common/Logging/Log.h') diff --git a/src/common/Logging/Log.h b/src/common/Logging/Log.h index 7a84d1120d3..17ba5682ceb 100644 --- a/src/common/Logging/Log.h +++ b/src/common/Logging/Log.h @@ -71,29 +71,29 @@ class TC_COMMON_API Log bool ShouldLog(std::string const& type, LogLevel level) const; bool SetLogLevel(std::string const& name, int32 level, bool isLogger = true); - template - inline void outMessage(std::string const& filter, LogLevel const level, Format&& fmt, Args&&... args) + template + void OutMessage(std::string_view filter, LogLevel const level, Trinity::FormatString fmt, Args&&... args) { - outMessage(filter, level, Trinity::StringFormat(std::forward(fmt), std::forward(args)...)); + this->OutMessageImpl(filter, level, Trinity::StringFormat(fmt, std::forward(args)...)); } - template - void outCommand(uint32 account, Format&& fmt, Args&&... args) + template + void OutCommand(uint32 account, Trinity::FormatString fmt, Args&&... args) { if (!ShouldLog("commands.gm", LOG_LEVEL_INFO)) return; - outCommand(Trinity::StringFormat(std::forward(fmt), std::forward(args)...), std::to_string(account)); + this->OutCommandImpl(Trinity::StringFormat(fmt, std::forward(args)...), std::to_string(account)); } - void outCharDump(char const* str, uint32 account_id, uint64 guid, char const* name); + void OutCharDump(char const* str, uint32 account_id, uint64 guid, char const* name); void SetRealmId(uint32 id); template void RegisterAppender() { - RegisterAppender(AppenderImpl::type, &CreateAppender); + this->RegisterAppender(AppenderImpl::type, &CreateAppender); } std::string const& GetLogsDir() const { return m_logsDir; } @@ -111,8 +111,8 @@ class TC_COMMON_API Log void ReadAppendersFromConfig(); void ReadLoggersFromConfig(); void RegisterAppender(uint8 index, AppenderCreatorFn appenderCreateFn); - void outMessage(std::string const& filter, LogLevel level, std::string&& message); - void outCommand(std::string&& message, std::string&& param1); + void OutMessageImpl(std::string_view filter, LogLevel level, std::string&& message); + void OutCommandImpl(std::string&& message, std::string&& param1); std::unordered_map appenderFactory; std::unordered_map> appenders; @@ -129,35 +129,15 @@ class TC_COMMON_API Log #define sLog Log::instance() -#define LOG_EXCEPTION_FREE(filterType__, level__, ...) \ - { \ - try \ - { \ - sLog->outMessage(filterType__, level__, __VA_ARGS__); \ - } \ - catch (std::exception& e) \ - { \ - sLog->outMessage("server", LOG_LEVEL_ERROR, "Wrong format occurred (%s) at %s:%u.", \ - e.what(), __FILE__, __LINE__); \ - } \ - } - #ifdef PERFORMANCE_PROFILING #define TC_LOG_MESSAGE_BODY(filterType__, level__, ...) ((void)0) #elif TRINITY_PLATFORM != TRINITY_PLATFORM_WINDOWS -void check_args(char const*, ...) ATTR_PRINTF(1, 2); -void check_args(std::string const&, ...); // This will catch format errors on build time #define TC_LOG_MESSAGE_BODY(filterType__, level__, ...) \ do { \ if (sLog->ShouldLog(filterType__, level__)) \ - { \ - if (false) \ - check_args(__VA_ARGS__); \ - \ - LOG_EXCEPTION_FREE(filterType__, level__, __VA_ARGS__); \ - } \ + sLog->OutMessage(filterType__, level__, __VA_ARGS__); \ } while (0) #else #define TC_LOG_MESSAGE_BODY(filterType__, level__, ...) \ @@ -165,7 +145,7 @@ void check_args(std::string const&, ...); __pragma(warning(disable:4127)) \ do { \ if (sLog->ShouldLog(filterType__, level__)) \ - LOG_EXCEPTION_FREE(filterType__, level__, __VA_ARGS__); \ + sLog->OutMessage(filterType__, level__, __VA_ARGS__); \ } while (0) \ __pragma(warning(pop)) #endif -- cgit v1.2.3