diff --git a/src/common/Logging/Log.h b/src/common/Logging/Log.h index d6e329a71d..74a115eac4 100644 --- a/src/common/Logging/Log.h +++ b/src/common/Logging/Log.h @@ -99,6 +99,18 @@ class TC_COMMON_API Log void CreateAppenderFromConfigLine(std::string const& name, std::string const& options); void CreateLoggerFromConfigLine(std::string const& name, std::string const& options); + template + static constexpr std::string_view make_string_view(StringOrStringView const& stringOrStringView) + { + return stringOrStringView; + } + + template + static consteval std::string_view make_string_view(char const(&chars)[CharArraySize]) + { + return { std::begin(chars), (chars[CharArraySize - 1] == '\0' ? CharArraySize - 1 : CharArraySize) }; + } + private: static std::string GetTimestampStr(); void write(std::unique_ptr msg) const; @@ -129,43 +141,40 @@ class TC_COMMON_API Log #define sLog Log::instance() -#ifdef PERFORMANCE_PROFILING -#define TC_LOG_MESSAGE_BODY(filterType__, level__, ...) ((void)0) -#elif TRINITY_PLATFORM != TRINITY_PLATFORM_WINDOWS - -// This will catch format errors on build time -#define TC_LOG_MESSAGE_BODY(filterType__, level__, ...) \ - do { \ - if (Log* logInstance = sLog; logInstance->ShouldLog(filterType__, level__)) \ - logInstance->OutMessage(filterType__, level__, __VA_ARGS__); \ +#define TC_LOG_MESSAGE_BODY_CORE(filterType__, level__, message__, ...) \ + do { \ + if (Log* logInstance = sLog; logInstance->ShouldLog(Log::make_string_view(filterType__), level__)) \ + logInstance->OutMessage(Log::make_string_view(filterType__), level__, Log::make_string_view(message__), ## __VA_ARGS__); \ } while (0) + +#ifdef PERFORMANCE_PROFILING +#define TC_LOG_MESSAGE_BODY(filterType__, level__, message__, ...) ((void)0) +#elif TRINITY_PLATFORM != TRINITY_PLATFORM_WINDOWS +#define TC_LOG_MESSAGE_BODY(filterType__, level__, message__, ...) TC_LOG_MESSAGE_BODY_CORE(filterType__, level__, message__, ## __VA_ARGS__) #else -#define TC_LOG_MESSAGE_BODY(filterType__, level__, ...) \ - __pragma(warning(push)) \ - __pragma(warning(disable:4127)) \ - do { \ - if (Log* logInstance = sLog; logInstance->ShouldLog(filterType__, level__)) \ - logInstance->OutMessage(filterType__, level__, __VA_ARGS__); \ - } while (0) \ +#define TC_LOG_MESSAGE_BODY(filterType__, level__, message__, ...) \ + __pragma(warning(push)) \ + __pragma(warning(disable:4127)) \ + TC_LOG_MESSAGE_BODY_CORE(filterType__, level__, message__, ## __VA_ARGS__) \ __pragma(warning(pop)) #endif -#define TC_LOG_TRACE(filterType__, ...) \ - TC_LOG_MESSAGE_BODY(filterType__, LOG_LEVEL_TRACE, __VA_ARGS__) +#define TC_LOG_TRACE(filterType__, message__, ...) \ + TC_LOG_MESSAGE_BODY(filterType__, LOG_LEVEL_TRACE, message__, ## __VA_ARGS__) -#define TC_LOG_DEBUG(filterType__, ...) \ - TC_LOG_MESSAGE_BODY(filterType__, LOG_LEVEL_DEBUG, __VA_ARGS__) +#define TC_LOG_DEBUG(filterType__, message__, ...) \ + TC_LOG_MESSAGE_BODY(filterType__, LOG_LEVEL_DEBUG, message__, ## __VA_ARGS__) -#define TC_LOG_INFO(filterType__, ...) \ - TC_LOG_MESSAGE_BODY(filterType__, LOG_LEVEL_INFO, __VA_ARGS__) +#define TC_LOG_INFO(filterType__, message__, ...) \ + TC_LOG_MESSAGE_BODY(filterType__, LOG_LEVEL_INFO, message__, ## __VA_ARGS__) -#define TC_LOG_WARN(filterType__, ...) \ - TC_LOG_MESSAGE_BODY(filterType__, LOG_LEVEL_WARN, __VA_ARGS__) +#define TC_LOG_WARN(filterType__, message__, ...) \ + TC_LOG_MESSAGE_BODY(filterType__, LOG_LEVEL_WARN, message__, ## __VA_ARGS__) -#define TC_LOG_ERROR(filterType__, ...) \ - TC_LOG_MESSAGE_BODY(filterType__, LOG_LEVEL_ERROR, __VA_ARGS__) +#define TC_LOG_ERROR(filterType__, message__, ...) \ + TC_LOG_MESSAGE_BODY(filterType__, LOG_LEVEL_ERROR, message__, ## __VA_ARGS__) -#define TC_LOG_FATAL(filterType__, ...) \ - TC_LOG_MESSAGE_BODY(filterType__, LOG_LEVEL_FATAL, __VA_ARGS__) +#define TC_LOG_FATAL(filterType__, message__, ...) \ + TC_LOG_MESSAGE_BODY(filterType__, LOG_LEVEL_FATAL, message__, ## __VA_ARGS__) #endif diff --git a/src/server/game/Maps/GridMap.cpp b/src/server/game/Maps/GridMap.cpp index 0d5f258767..d61594736c 100644 --- a/src/server/game/Maps/GridMap.cpp +++ b/src/server/game/Maps/GridMap.cpp @@ -108,8 +108,8 @@ GridMap::LoadResult GridMap::loadData(char const* filename) return LoadResult::Ok; } - TC_LOG_ERROR("maps", "Map file '{}' is from an incompatible map version (%.*s v{}), %.*s v{} is expected. Please pull your source, recompile tools and recreate maps using the updated mapextractor, then replace your old map files with new files. If you still have problems search on forum for error TCE00018.", - filename, 4, header.mapMagic.data(), header.versionMagic, 4, MapMagic.data(), MapVersionMagic); + TC_LOG_ERROR("maps", "Map file '{}' is from an incompatible map version ({} v{}), {} v{} is expected. Please pull your source, recompile tools and recreate maps using the updated mapextractor, then replace your old map files with new files. If you still have problems search on forum for error TCE00018.", + filename, std::string_view(header.mapMagic.data(), 4), header.versionMagic, std::string_view(MapMagic.data(), 4), MapVersionMagic); fclose(in); return LoadResult::InvalidFile; } diff --git a/src/server/game/Maps/TerrainMgr.cpp b/src/server/game/Maps/TerrainMgr.cpp index 189108a74d..b2faa91a94 100644 --- a/src/server/game/Maps/TerrainMgr.cpp +++ b/src/server/game/Maps/TerrainMgr.cpp @@ -96,8 +96,8 @@ bool TerrainInfo::ExistMap(uint32 mapid, int32 gx, int32 gy, bool log /*= true*/ if (header.mapMagic != MapMagic || header.versionMagic != MapVersionMagic) { if (log) - TC_LOG_ERROR("maps", "Map file '{}' is from an incompatible map version (%.*s v{}), %.*s v{} is expected. Please pull your source, recompile tools and recreate maps using the updated mapextractor, then replace your old map files with new files. If you still have problems search on forum for error TCE00018.", - fileName, 4, header.mapMagic.data(), header.versionMagic, 4, MapMagic.data(), MapVersionMagic); + TC_LOG_ERROR("maps", "Map file '{}' is from an incompatible map version ({} v{}), {} v{} is expected. Please pull your source, recompile tools and recreate maps using the updated mapextractor, then replace your old map files with new files. If you still have problems search on forum for error TCE00018.", + fileName, std::string_view(header.mapMagic.data(), 4), header.versionMagic, std::string_view(MapMagic.data(), 4), MapVersionMagic); } else ret = true; diff --git a/src/server/scripts/World/chat_log.cpp b/src/server/scripts/World/chat_log.cpp index cec8cf6191..74178d7333 100644 --- a/src/server/scripts/World/chat_log.cpp +++ b/src/server/scripts/World/chat_log.cpp @@ -22,11 +22,11 @@ #include "Log.h" #include "Player.h" -#define TC_LOG_CHAT(TYPE, ...) \ - if (lang != LANG_ADDON && lang != LANG_ADDON_LOGGED) \ - TC_LOG_DEBUG("chat.log." TYPE, __VA_ARGS__); \ - else \ - TC_LOG_DEBUG("chat.log.addon." TYPE, __VA_ARGS__); +#define TC_LOG_CHAT(TYPE, MESSAGE, ...) \ + if (lang != LANG_ADDON && lang != LANG_ADDON_LOGGED) \ + TC_LOG_DEBUG("chat.log." TYPE, MESSAGE, __VA_ARGS__); \ + else \ + TC_LOG_DEBUG("chat.log.addon." TYPE, MESSAGE, __VA_ARGS__); class ChatLogScript : public PlayerScript {