Core/Logging: Enable perfect forwarding for logging format and args.

* Handle timestamp parsing though cppformat.
* Change a wrong forward -> move

(cherry picked from commit 026ceb85b9)
This commit is contained in:
Naios
2015-07-21 23:17:00 +02:00
parent b0255927f0
commit e011ae63d5
3 changed files with 32 additions and 13 deletions

View File

@@ -317,7 +317,15 @@ void Map::SwitchGridContainers(Creature* obj, bool on)
if (!IsGridLoaded(GridCoord(cell.data.Part.grid_x, cell.data.Part.grid_y)))
return;
TC_LOG_DEBUG("maps", "Switch object %s from grid[%u, %u] %u", obj->GetGUID().ToString().c_str(), cell.data.Part.grid_x, cell.data.Part.grid_y, on);
if (sLog->ShouldLog("maps", LOG_LEVEL_DEBUG))
{
// Extract bitfield values
uint32 const grid_x = cell.data.Part.grid_x;
uint32 const grid_y = cell.data.Part.grid_y;
TC_LOG_DEBUG("maps", "Switch object %s from grid[%u, %u] %u", obj->GetGUID().ToString().c_str(), grid_x, grid_y, on);
}
NGridType *ngrid = getNGrid(cell.GridX(), cell.GridY());
ASSERT(ngrid != NULL);
@@ -354,7 +362,15 @@ void Map::SwitchGridContainers(GameObject* obj, bool on)
if (!IsGridLoaded(GridCoord(cell.data.Part.grid_x, cell.data.Part.grid_y)))
return;
TC_LOG_DEBUG("maps", "Switch object %s from grid[%u, %u] %u", obj->GetGUID().ToString().c_str(), cell.data.Part.grid_x, cell.data.Part.grid_y, on);
if (sLog->ShouldLog("maps", LOG_LEVEL_DEBUG))
{
// Extract bitfield values
uint32 const grid_x = cell.data.Part.grid_x;
uint32 const grid_y = cell.data.Part.grid_y;
TC_LOG_DEBUG("maps", "Switch object %s from grid[%u, %u] %u", obj->GetGUID().ToString().c_str(), grid_x, grid_y, on);
}
NGridType *ngrid = getNGrid(cell.GridX(), cell.GridY());
ASSERT(ngrid != NULL);

View File

@@ -269,7 +269,7 @@ void Log::write(std::unique_ptr<LogMessage>&& msg) const
if (_ioService)
{
auto logOperation = std::shared_ptr<LogOperation>(new LogOperation(logger, std::forward<std::unique_ptr<LogMessage>>(msg)));
auto logOperation = std::shared_ptr<LogOperation>(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 */)

View File

@@ -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<typename... Args>
inline void outMessage(std::string const& filter, LogLevel const level, const char* fmt, Args const&... args)
template<typename Format, typename... Args>
inline void outMessage(std::string const& filter, LogLevel const level, Format&& fmt, Args&&... args)
{
write(Trinity::make_unique<LogMessage>(level, filter, Trinity::StringFormat(fmt, args...)));
write(Trinity::make_unique<LogMessage>(level, filter,
Trinity::StringFormat(std::forward<Format>(fmt), std::forward<Args>(args)...)));
}
template<typename... Args>
void outCommand(uint32 account, const char* fmt, Args const&... args)
template<typename Format, typename... Args>
void outCommand(uint32 account, Format&& fmt, Args&&... args)
{
if (!ShouldLog("commands.gm", LOG_LEVEL_INFO))
return;
std::unique_ptr<LogMessage> msg = Trinity::make_unique<LogMessage>(LOG_LEVEL_INFO, "commands.gm", std::move(Trinity::StringFormat(fmt, args...)));
std::unique_ptr<LogMessage> msg =
Trinity::make_unique<LogMessage>(LOG_LEVEL_INFO, "commands.gm",
Trinity::StringFormat(std::forward<Format>(fmt), std::forward<Args>(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__, ...) \