hints: Renamed SDL_HINT_LOG_BACKENDS to SDL_DEBUG_LOGGING.

This still logs backend choices, but we might use it for other things. For
example, what Android device is being used, or all the devices we enumerated,
etc.

Ideally this eventually logs all the stuff we often have to ask followup
questions about.
This commit is contained in:
Ryan C. Gordon
2025-07-22 13:19:30 -04:00
parent af1c05fd58
commit 07ef532681
11 changed files with 29 additions and 25 deletions

View File

@@ -4396,26 +4396,29 @@ extern "C" {
#define SDL_HINT_PEN_TOUCH_EVENTS "SDL_PEN_TOUCH_EVENTS" #define SDL_HINT_PEN_TOUCH_EVENTS "SDL_PEN_TOUCH_EVENTS"
/** /**
* A variable controlling whether SDL backend information is logged. * A variable controlling whether SDL logs some debug information.
* *
* The variable can be set to the following values: * The variable can be set to the following values:
* *
* - "0": Subsystem information will not be logged. (default) * - "0": SDL debug information will not be logged. (default)
* - "1": Subsystem information will be logged. * - "1": SDL debug information will be logged.
* *
* This is generally meant to be used as an environment variable to let * This is generally meant to be used as an environment variable to let
* end-users report what subsystems were chosen on their system, to aid in * end-users report what subsystems were chosen on their system, perhaps what
* debugging. Logged information is sent through SDL_Log(), which means by * sort of hardware they are running on, etc, to aid in debugging. Logged
* default they appear on stdout on most platforms or maybe * information is sent through SDL_Log(), which means by default they appear
* OutputDebugString() on Windows, and can be funneled by the app with * on stdout on most platforms, or maybe OutputDebugString() on Windows, and
* SDL_SetLogOutputFunction(), etc. * can be funneled by the app with SDL_SetLogOutputFunction(), etc.
*
* The specific output might change between SDL versions; more information
* might be deemed useful in the future.
* *
* This hint can be set anytime, but the specific logs are generated during * This hint can be set anytime, but the specific logs are generated during
* subsystem init. * subsystem init.
* *
* \since This hint is available since SDL 3.4.0. * \since This hint is available since SDL 3.4.0.
*/ */
#define SDL_HINT_LOG_BACKENDS "SDL_LOG_BACKENDS" #define SDL_HINT_DEBUG_LOGGING "SDL_DEBUG_LOGGING"
/** /**
* An enumeration of hint priorities. * An enumeration of hint priorities.

View File

@@ -553,11 +553,12 @@ char *SDL_CreateDeviceName(Uint16 vendor, Uint16 product, const char *vendor_nam
return name; return name;
} }
void SDL_LogBackend(const char *subsystem, const char *backend) #define SDL_DEBUG_LOG_INTRO "SDL_DEBUG: "
void SDL_DebugLogBackend(const char *subsystem, const char *backend)
{ {
if (SDL_GetHintBoolean(SDL_HINT_LOG_BACKENDS, false)) { if (SDL_GetHintBoolean(SDL_HINT_DEBUG_LOGGING, false)) {
SDL_Log("SDL_BACKEND: %s -> '%s'", subsystem, backend); SDL_Log(SDL_DEBUG_LOG_INTRO "chose %s backend '%s'", subsystem, backend);
} }
} }

View File

@@ -76,6 +76,6 @@ extern const char *SDL_GetPersistentString(const char *string);
extern char *SDL_CreateDeviceName(Uint16 vendor, Uint16 product, const char *vendor_name, const char *product_name, const char *default_name); extern char *SDL_CreateDeviceName(Uint16 vendor, Uint16 product, const char *vendor_name, const char *product_name, const char *default_name);
// Log what backend a subsystem chose, if a hint was set to do so. Useful for debugging. // Log what backend a subsystem chose, if a hint was set to do so. Useful for debugging.
extern void SDL_LogBackend(const char *subsystem, const char *backend); extern void SDL_DebugLogBackend(const char *subsystem, const char *backend);
#endif // SDL_utils_h_ #endif // SDL_utils_h_

View File

@@ -1007,7 +1007,7 @@ bool SDL_InitAudio(const char *driver_name)
} }
if (initialized) { if (initialized) {
SDL_LogBackend("audio", current_audio.name); SDL_DebugLogBackend("audio", current_audio.name);
} else { } else {
// specific drivers will set the error message if they fail, but otherwise we do it here. // specific drivers will set the error message if they fail, but otherwise we do it here.
if (!tried_to_init) { if (!tried_to_init) {

View File

@@ -1525,7 +1525,7 @@ bool SDL_CameraInit(const char *driver_name)
} }
if (initialized) { if (initialized) {
SDL_LogBackend("camera", camera_driver.name); SDL_DebugLogBackend("camera", camera_driver.name);
} else { } else {
// specific drivers will set the error message if they fail, but otherwise we do it here. // specific drivers will set the error message if they fail, but otherwise we do it here.
if (!tried_to_init) { if (!tried_to_init) {

View File

@@ -711,7 +711,7 @@ SDL_GPUDevice *SDL_CreateGPUDeviceWithProperties(SDL_PropertiesID props)
selectedBackend = SDL_GPUSelectBackend(props); selectedBackend = SDL_GPUSelectBackend(props);
if (selectedBackend != NULL) { if (selectedBackend != NULL) {
SDL_LogBackend("gpu", selectedBackend->name); SDL_DebugLogBackend("gpu", selectedBackend->name);
debug_mode = SDL_GetBooleanProperty(props, SDL_PROP_GPU_DEVICE_CREATE_DEBUGMODE_BOOLEAN, true); debug_mode = SDL_GetBooleanProperty(props, SDL_PROP_GPU_DEVICE_CREATE_DEBUGMODE_BOOLEAN, true);
preferLowPower = SDL_GetBooleanProperty(props, SDL_PROP_GPU_DEVICE_CREATE_PREFERLOWPOWER_BOOLEAN, false); preferLowPower = SDL_GetBooleanProperty(props, SDL_PROP_GPU_DEVICE_CREATE_PREFERLOWPOWER_BOOLEAN, false);

View File

@@ -512,12 +512,12 @@ static void MaybeInitializeLibUring(void)
{ {
if (SDL_ShouldInit(&liburing_init)) { if (SDL_ShouldInit(&liburing_init)) {
if (LoadLibUring()) { if (LoadLibUring()) {
SDL_LogBackend("asyncio", "liburing"); SDL_DebugLogBackend("asyncio", "liburing");
CreateAsyncIOQueue = SDL_SYS_CreateAsyncIOQueue_liburing; CreateAsyncIOQueue = SDL_SYS_CreateAsyncIOQueue_liburing;
QuitAsyncIO = SDL_SYS_QuitAsyncIO_liburing; QuitAsyncIO = SDL_SYS_QuitAsyncIO_liburing;
AsyncIOFromFile = SDL_SYS_AsyncIOFromFile_liburing; AsyncIOFromFile = SDL_SYS_AsyncIOFromFile_liburing;
} else { // can't use liburing? Use the "generic" threadpool implementation instead. } else { // can't use liburing? Use the "generic" threadpool implementation instead.
SDL_LogBackend("asyncio", "generic"); SDL_DebugLogBackend("asyncio", "generic");
CreateAsyncIOQueue = SDL_SYS_CreateAsyncIOQueue_Generic; CreateAsyncIOQueue = SDL_SYS_CreateAsyncIOQueue_Generic;
QuitAsyncIO = SDL_SYS_QuitAsyncIO_Generic; QuitAsyncIO = SDL_SYS_QuitAsyncIO_Generic;
AsyncIOFromFile = SDL_SYS_AsyncIOFromFile_Generic; AsyncIOFromFile = SDL_SYS_AsyncIOFromFile_Generic;

View File

@@ -511,12 +511,12 @@ static void MaybeInitializeWinIoRing(void)
{ {
if (SDL_ShouldInit(&ioring_init)) { if (SDL_ShouldInit(&ioring_init)) {
if (LoadWinIoRing()) { if (LoadWinIoRing()) {
SDL_LogBackend("asyncio", "ioring"); SDL_DebugLogBackend("asyncio", "ioring");
CreateAsyncIOQueue = SDL_SYS_CreateAsyncIOQueue_ioring; CreateAsyncIOQueue = SDL_SYS_CreateAsyncIOQueue_ioring;
QuitAsyncIO = SDL_SYS_QuitAsyncIO_ioring; QuitAsyncIO = SDL_SYS_QuitAsyncIO_ioring;
AsyncIOFromFile = SDL_SYS_AsyncIOFromFile_ioring; AsyncIOFromFile = SDL_SYS_AsyncIOFromFile_ioring;
} else { // can't use ioring? Use the "generic" threadpool implementation instead. } else { // can't use ioring? Use the "generic" threadpool implementation instead.
SDL_LogBackend("asyncio", "generic"); SDL_DebugLogBackend("asyncio", "generic");
CreateAsyncIOQueue = SDL_SYS_CreateAsyncIOQueue_Generic; CreateAsyncIOQueue = SDL_SYS_CreateAsyncIOQueue_Generic;
QuitAsyncIO = SDL_SYS_QuitAsyncIO_Generic; QuitAsyncIO = SDL_SYS_QuitAsyncIO_Generic;
AsyncIOFromFile = SDL_SYS_AsyncIOFromFile_Generic; AsyncIOFromFile = SDL_SYS_AsyncIOFromFile_Generic;

View File

@@ -1064,7 +1064,7 @@ SDL_Renderer *SDL_CreateRendererWithProperties(SDL_PropertiesID props)
} }
if (rc) { if (rc) {
SDL_LogBackend("render", renderer->name); SDL_DebugLogBackend("render", renderer->name);
} else { } else {
if (driver_name) { if (driver_name) {
SDL_SetError("%s not available", driver_name); SDL_SetError("%s not available", driver_name);

View File

@@ -119,7 +119,7 @@ SDL_Storage *SDL_OpenTitleStorage(const char *override, SDL_PropertiesID props)
} }
} }
if (storage) { if (storage) {
SDL_LogBackend("title_storage", titlebootstrap[i]->name); SDL_DebugLogBackend("title_storage", titlebootstrap[i]->name);
} else { } else {
if (driver_name) { if (driver_name) {
SDL_SetError("%s not available", driver_name); SDL_SetError("%s not available", driver_name);
@@ -163,7 +163,7 @@ SDL_Storage *SDL_OpenUserStorage(const char *org, const char *app, SDL_Propertie
} }
} }
if (storage) { if (storage) {
SDL_LogBackend("user_storage", userbootstrap[i]->name); SDL_DebugLogBackend("user_storage", userbootstrap[i]->name);
} else { } else {
if (driver_name) { if (driver_name) {
SDL_SetError("%s not available", driver_name); SDL_SetError("%s not available", driver_name);

View File

@@ -680,7 +680,7 @@ bool SDL_VideoInit(const char *driver_name)
} }
} }
if (video) { if (video) {
SDL_LogBackend("video", bootstrap[i]->name); SDL_DebugLogBackend("video", bootstrap[i]->name);
} else { } else {
if (driver_name) { if (driver_name) {
SDL_SetError("%s not available", driver_name); SDL_SetError("%s not available", driver_name);