From 33cc487ae4849fb05344a42e944c78e8f992cef4 Mon Sep 17 00:00:00 2001 From: Gleb Mazovetskiy Date: Sat, 6 Jul 2024 10:28:21 +0100 Subject: [PATCH] Add single-argument logging overloads Avoids going through `fmt` for single-argument log calls. --- Source/utils/log.hpp | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/Source/utils/log.hpp b/Source/utils/log.hpp index 45a060d96..26c429527 100644 --- a/Source/utils/log.hpp +++ b/Source/utils/log.hpp @@ -63,6 +63,11 @@ std::string format(std::string_view fmt, Args &&...args) } // namespace detail +inline void Log(std::string_view str) +{ + SDL_Log("%.*s", static_cast(str.size()), str.data()); +} + template void Log(std::string_view fmt, Args &&...args) { @@ -70,6 +75,11 @@ void Log(std::string_view fmt, Args &&...args) SDL_Log("%s", str.c_str()); } +inline void LogVerbose(LogCategory category, std::string_view str) +{ + SDL_LogVerbose(static_cast(category), "%.*s", static_cast(str.size()), str.data()); +} + template void LogVerbose(LogCategory category, std::string_view fmt, Args &&...args) { @@ -84,6 +94,11 @@ void LogVerbose(std::string_view fmt, Args &&...args) LogVerbose(defaultCategory, fmt, std::forward(args)...); } +inline void LogDebug(LogCategory category, std::string_view str) +{ + SDL_LogDebug(static_cast(category), "%.*s", static_cast(str.size()), str.data()); +} + template void LogDebug(LogCategory category, std::string_view fmt, Args &&...args) { @@ -98,6 +113,11 @@ void LogDebug(std::string_view fmt, Args &&...args) LogDebug(defaultCategory, fmt, std::forward(args)...); } +inline void LogInfo(LogCategory category, std::string_view str) +{ + SDL_LogInfo(static_cast(category), "%.*s", static_cast(str.size()), str.data()); +} + template void LogInfo(LogCategory category, std::string_view fmt, Args &&...args) { @@ -111,6 +131,11 @@ void LogInfo(std::string_view fmt, Args &&...args) LogInfo(defaultCategory, fmt, std::forward(args)...); } +inline void LogWarn(LogCategory category, std::string_view str) +{ + SDL_LogWarn(static_cast(category), "%.*s", static_cast(str.size()), str.data()); +} + template void LogWarn(LogCategory category, std::string_view fmt, Args &&...args) { @@ -124,6 +149,11 @@ void LogWarn(std::string_view fmt, Args &&...args) LogWarn(defaultCategory, fmt, std::forward(args)...); } +inline void LogError(LogCategory category, std::string_view str) +{ + SDL_LogError(static_cast(category), "%.*s", static_cast(str.size()), str.data()); +} + template void LogError(LogCategory category, std::string_view fmt, Args &&...args) { @@ -137,6 +167,11 @@ void LogError(std::string_view fmt, Args &&...args) LogError(defaultCategory, fmt, std::forward(args)...); } +inline void LogCritical(LogCategory category, std::string_view str) +{ + SDL_LogCritical(static_cast(category), "%.*s", static_cast(str.size()), str.data()); +} + template void LogCritical(LogCategory category, std::string_view fmt, Args &&...args) { @@ -150,6 +185,12 @@ void LogCritical(std::string_view fmt, Args &&...args) LogCritical(defaultCategory, fmt, std::forward(args)...); } +inline void LogMessageV(LogCategory category, LogPriority priority, std::string_view str) +{ + SDL_LogMessage(static_cast(category), static_cast(priority), + "%.*s", static_cast(str.size()), str.data()); +} + template void LogMessageV(LogCategory category, LogPriority priority, std::string_view fmt, Args &&...args) {