From e011ae63d5ef117e3462e538089ca58fb4777195 Mon Sep 17 00:00:00 2001 From: Naios Date: Tue, 21 Jul 2015 23:17:00 +0200 Subject: Core/Logging: Enable perfect forwarding for logging format and args. * Handle timestamp parsing though cppformat. * Change a wrong forward -> move (cherry picked from commit 026ceb85b9e0e870d95cea42895e867198c156dd) --- src/server/shared/Logging/Log.cpp | 7 +++---- src/server/shared/Logging/Log.h | 18 +++++++++++------- 2 files changed, 14 insertions(+), 11 deletions(-) (limited to 'src/server/shared') diff --git a/src/server/shared/Logging/Log.cpp b/src/server/shared/Logging/Log.cpp index a2150733c6b..6c2580b3168 100644 --- a/src/server/shared/Logging/Log.cpp +++ b/src/server/shared/Logging/Log.cpp @@ -269,7 +269,7 @@ void Log::write(std::unique_ptr&& msg) const if (_ioService) { - auto logOperation = std::shared_ptr(new LogOperation(logger, std::forward>(msg))); + auto logOperation = std::shared_ptr(new LogOperation(logger, std::move(msg))); _ioService->post(_strand->wrap([logOperation](){ logOperation->call(); })); } @@ -290,9 +290,8 @@ std::string Log::GetTimestampStr() // HH hour (2 digits 00-23) // MM minutes (2 digits 00-59) // SS seconds (2 digits 00-59) - char buf[20]; - snprintf(buf, 20, "%04d-%02d-%02d_%02d-%02d-%02d", aTm.tm_year+1900, aTm.tm_mon+1, aTm.tm_mday, aTm.tm_hour, aTm.tm_min, aTm.tm_sec); - return std::string(buf); + return Trinity::StringFormat("%04d-%02d-%02d_%02d-%02d-%02d", + aTm.tm_year + 1900, aTm.tm_mon + 1, aTm.tm_mday, aTm.tm_hour, aTm.tm_min, aTm.tm_sec); } bool Log::SetLogLevel(std::string const& name, const char* newLevelc, bool isLogger /* = true */) diff --git a/src/server/shared/Logging/Log.h b/src/server/shared/Logging/Log.h index 5b3782fce55..ab7b2169ed2 100644 --- a/src/server/shared/Logging/Log.h +++ b/src/server/shared/Logging/Log.h @@ -62,19 +62,22 @@ class Log bool ShouldLog(std::string const& type, LogLevel level) const; bool SetLogLevel(std::string const& name, char const* level, bool isLogger = true); - template - inline void outMessage(std::string const& filter, LogLevel const level, const char* fmt, Args const&... args) + template + inline void outMessage(std::string const& filter, LogLevel const level, Format&& fmt, Args&&... args) { - write(Trinity::make_unique(level, filter, Trinity::StringFormat(fmt, args...))); + write(Trinity::make_unique(level, filter, + Trinity::StringFormat(std::forward(fmt), std::forward(args)...))); } - template - void outCommand(uint32 account, const char* fmt, Args const&... args) + template + void outCommand(uint32 account, Format&& fmt, Args&&... args) { if (!ShouldLog("commands.gm", LOG_LEVEL_INFO)) return; - std::unique_ptr msg = Trinity::make_unique(LOG_LEVEL_INFO, "commands.gm", std::move(Trinity::StringFormat(fmt, args...))); + std::unique_ptr msg = + Trinity::make_unique(LOG_LEVEL_INFO, "commands.gm", + Trinity::StringFormat(std::forward(fmt), std::forward(args)...)); msg->param1 = std::to_string(account); @@ -160,7 +163,8 @@ inline bool Log::ShouldLog(std::string const& type, LogLevel level) const } #if PLATFORM != PLATFORM_WINDOWS -void check_args(const char* format, ...) ATTR_PRINTF(1, 2); +void check_args(const char*, ...) 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__, ...) \ -- cgit v1.2.3