96 lines
3.9 KiB
C++
96 lines
3.9 KiB
C++
#pragma once
|
|
#include <SDL3/SDL_log.h>
|
|
namespace hdk::sdl {
|
|
/**
|
|
* @brief Log instances represent logging categories: Application, Error, System, Audio, Video, Render, Input, Test,
|
|
* etc.
|
|
*/
|
|
class Log {
|
|
public:
|
|
const int category;
|
|
static const Log Application;
|
|
Log(int category)
|
|
: category(category) { }
|
|
/** https://wiki.libsdl.org/SDL3/SDL_GetDefaultLogOutputFunction */
|
|
static SDL_LogOutputFunction GetDefaultOutputFunction() { return SDL_GetDefaultLogOutputFunction(); }
|
|
/** https://wiki.libsdl.org/SDL3/SDL_GetLogOutputFunction */
|
|
static void GetOutputFunction(SDL_LogOutputFunction* callback, void** userdata) {
|
|
SDL_GetLogOutputFunction(callback, userdata);
|
|
}
|
|
/** https://wiki.libsdl.org/SDL3/SDL_GetLogPriority */
|
|
SDL_LogPriority GetPriority() { return SDL_GetLogPriority(category); }
|
|
/** https://wiki.libsdl.org/SDL3/SDL_Log */
|
|
|
|
/** https://wiki.libsdl.org/SDL3/SDL_LogCritical */
|
|
void Critical(const char* fmt, ...) const {
|
|
va_list args;
|
|
va_start(args, fmt);
|
|
LogMessageV(SDL_LOG_PRIORITY_CRITICAL, fmt, args);
|
|
va_end(args);
|
|
}
|
|
/** https://wiki.libsdl.org/SDL3/SDL_LogDebug */
|
|
void Debug(const char* fmt, ...) const {
|
|
va_list args;
|
|
va_start(args, fmt);
|
|
LogMessageV(SDL_LOG_PRIORITY_DEBUG, fmt, args);
|
|
va_end(args);
|
|
}
|
|
/** https://wiki.libsdl.org/SDL3/SDL_LogError */
|
|
void Error(const char* fmt, ...) const {
|
|
va_list args;
|
|
va_start(args, fmt);
|
|
LogMessageV(SDL_LOG_PRIORITY_ERROR, fmt, args);
|
|
va_end(args);
|
|
}
|
|
/** https://wiki.libsdl.org/SDL3/SDL_LogInfo */
|
|
void Info(const char* fmt, ...) const {
|
|
va_list args;
|
|
va_start(args, fmt);
|
|
LogMessageV(SDL_LOG_PRIORITY_INFO, fmt, args);
|
|
va_end(args);
|
|
}
|
|
/** https://wiki.libsdl.org/SDL3/SDL_LogMessage */
|
|
void LogMessage(SDL_LogPriority priority, const char* fmt, ...) const {
|
|
va_list args;
|
|
va_start(args, fmt);
|
|
LogMessageV(priority, fmt, args);
|
|
va_end(args);
|
|
}
|
|
/** https://wiki.libsdl.org/SDL3/SDL_LogMessageV */
|
|
void LogMessageV(SDL_LogPriority priority, const char* fmt, va_list args) const {
|
|
SDL_LogMessageV(category, priority, fmt, args);
|
|
}
|
|
/** https://wiki.libsdl.org/SDL3/SDL_LogTrace */
|
|
void Trace(const char* fmt, ...) const {
|
|
va_list args;
|
|
va_start(args, fmt);
|
|
LogMessageV(SDL_LOG_PRIORITY_TRACE, fmt, args);
|
|
va_end(args);
|
|
}
|
|
/** https://wiki.libsdl.org/SDL3/SDL_LogVerbose */
|
|
void Verbose(const char* fmt, ...) const {
|
|
va_list args;
|
|
va_start(args, fmt);
|
|
LogMessageV(SDL_LOG_PRIORITY_VERBOSE, fmt, args);
|
|
va_end(args);
|
|
}
|
|
/** https://wiki.libsdl.org/SDL3/SDL_LogWarn */
|
|
void Warn(const char* fmt, ...) const {
|
|
va_list args;
|
|
va_start(args, fmt);
|
|
LogMessageV(SDL_LOG_PRIORITY_WARN, fmt, args);
|
|
va_end(args);
|
|
}
|
|
/** https://wiki.libsdl.org/SDL3/SDL_ResetLogPriorities */
|
|
static void ResetPriorities() { SDL_ResetLogPriorities(); }
|
|
/** https://wiki.libsdl.org/SDL3/SDL_SetLogOutputFunction */
|
|
static void SetOutputFunction(SDL_LogOutputFunction callback, void* userdata) { SDL_SetLogOutputFunction(callback, userdata); }
|
|
/** https://wiki.libsdl.org/SDL3/SDL_SetLogPriorities */
|
|
static void SetPriorities(SDL_LogPriority priority) { SDL_SetLogPriorities(priority); }
|
|
/** https://wiki.libsdl.org/SDL3/SDL_SetLogPriority */
|
|
void SetPriority(SDL_LogPriority priority) { SDL_SetLogPriority(category, priority); }
|
|
/** @todo https://wiki.libsdl.org/SDL3/SDL_SetLogPriorityPrefix */
|
|
// static Log Application(){static Log app(SDL_LOG_CATEGORY_APPLICATION); return app;}
|
|
};
|
|
inline const Log Log::Application(SDL_LOG_CATEGORY_APPLICATION);
|
|
} |