Skip to content

Commit

Permalink
Add single-argument logging overloads
Browse files Browse the repository at this point in the history
Avoids going through `fmt` for single-argument log calls.
  • Loading branch information
glebm committed Jul 6, 2024
1 parent 01cbfb6 commit 1a39f78
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions Source/utils/log.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,23 @@ 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)
{
auto str = detail::format(fmt, std::forward<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)
{
Expand All @@ -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)
{
Expand All @@ -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)
{
Expand All @@ -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)
{
Expand All @@ -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)
{
Expand All @@ -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)
{
Expand All @@ -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)
{
Expand Down

0 comments on commit 1a39f78

Please sign in to comment.