Does SDL2 or SDL3 have any shorthand for logging to different log levels? I know there’s the SDL_Log
which logs application category to info level. Are there any shorthands for logging to other log levels? Writing SDL_LogError(SDL_LOG_CATEGORY_APPLICATION)
every time becomes verbose quickly.
Of course I can define my own macros, but I’d like to see if there’s an “official” way.
Specifically for your example, there is the function SDL_Log("Formatted text string: %s", "Variables");
For the other functions, I would use a precompiler directive to create my own shorthand.
#include <SDL2/SDL.h>
#define MY_APP SDL_LOG_CATEGORY_APPLICATION
int main()
{
SDL_Init(SDL_INIT_EVERYTHING);
SDL_LogSetAllPriority(SDL_LOG_PRIORITY_INFO);
//SDL_LogSetAllPriority(SDL_LOG_PRIORITY_VERBOSE);
//SDL_LogSetAllPriority(SDL_LOG_PRIORITY_DEBUG);
SDL_Log("This is using the function SDL_Log");
SDL_LogError(MY_APP, "This uses a precompiler define and SDL_LogError");
SDL_LogError(1, "You could also use values like %d or %d, but...", 1, 8);
SDL_LogError(8, "This is less desirable as SDL could potentially change values of the enum");
SDL_LogCritical(MY_APP, "Thanks to the SDL_LogSetAllPriority() above, this is now on screen");
SDL_LogWarn(MY_APP, "Warn");
SDL_LogVerbose(MY_APP, "This only shows up if you uncomment the verbose or debug SetPriority above.");
SDL_LogDebug(MY_APP, "Verbose and Debug priority seem to have the same effects.");
SDL_Quit();
}
You might also like the other log functions at the bottom of this page: SDL_Log
Yeah, there’s SDL_Log
for the INFO severity, I wish there are ones for warning and error as well. Like SDL_LogW
or something. I will define macros anyways.
I tinkered a bit more with the code above, it took me a bit to figure out what LogVerbose and LogDebug were doing (mostly they are just ignored by SDL until the proper priority is set).