Browse Source

Add single-argument logging overloads

Avoids going through `fmt` for single-argument log calls.
pull/7182/head
Gleb Mazovetskiy 2 years ago
parent
commit
33cc487ae4
  1. 41
      Source/utils/log.hpp

41
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<int>(str.size()), str.data());
}
template <typename... Args>
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<int>(category), "%.*s", static_cast<int>(str.size()), str.data());
}
template <typename... Args>
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>(args)...);
}
inline void LogDebug(LogCategory category, std::string_view str)
{
SDL_LogDebug(static_cast<int>(category), "%.*s", static_cast<int>(str.size()), str.data());
}
template <typename... Args>
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>(args)...);
}
inline void LogInfo(LogCategory category, std::string_view str)
{
SDL_LogInfo(static_cast<int>(category), "%.*s", static_cast<int>(str.size()), str.data());
}
template <typename... Args>
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>(args)...);
}
inline void LogWarn(LogCategory category, std::string_view str)
{
SDL_LogWarn(static_cast<int>(category), "%.*s", static_cast<int>(str.size()), str.data());
}
template <typename... Args>
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>(args)...);
}
inline void LogError(LogCategory category, std::string_view str)
{
SDL_LogError(static_cast<int>(category), "%.*s", static_cast<int>(str.size()), str.data());
}
template <typename... Args>
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>(args)...);
}
inline void LogCritical(LogCategory category, std::string_view str)
{
SDL_LogCritical(static_cast<int>(category), "%.*s", static_cast<int>(str.size()), str.data());
}
template <typename... Args>
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>(args)...);
}
inline void LogMessageV(LogCategory category, LogPriority priority, std::string_view str)
{
SDL_LogMessage(static_cast<int>(category), static_cast<SDL_LogPriority>(priority),
"%.*s", static_cast<int>(str.size()), str.data());
}
template <typename... Args>
void LogMessageV(LogCategory category, LogPriority priority, std::string_view fmt, Args &&...args)
{

Loading…
Cancel
Save