Simplified the default log category logic

Now it's much clearer and easier to tweak the defaults
This commit is contained in:
Sam Lantinga 2024-01-27 15:38:26 -08:00
parent a7a98d8bbb
commit 4fba663368

View file

@ -41,11 +41,6 @@
/* The size of the stack buffer to use for rendering log messages. */ /* The size of the stack buffer to use for rendering log messages. */
#define SDL_MAX_LOG_MESSAGE_STACK 256 #define SDL_MAX_LOG_MESSAGE_STACK 256
#define DEFAULT_PRIORITY SDL_LOG_PRIORITY_ERROR
#define DEFAULT_ASSERT_PRIORITY SDL_LOG_PRIORITY_WARN
#define DEFAULT_APPLICATION_PRIORITY SDL_LOG_PRIORITY_INFO
#define DEFAULT_TEST_PRIORITY SDL_LOG_PRIORITY_VERBOSE
typedef struct SDL_LogLevel typedef struct SDL_LogLevel
{ {
int category; int category;
@ -57,10 +52,8 @@ typedef struct SDL_LogLevel
static void SDLCALL SDL_LogOutput(void *userdata, int category, SDL_LogPriority priority, const char *message); static void SDLCALL SDL_LogOutput(void *userdata, int category, SDL_LogPriority priority, const char *message);
static SDL_LogLevel *SDL_loglevels; static SDL_LogLevel *SDL_loglevels;
static SDL_LogPriority SDL_default_priority = DEFAULT_PRIORITY; static SDL_bool SDL_forced_priority = SDL_FALSE;
static SDL_LogPriority SDL_assert_priority = DEFAULT_ASSERT_PRIORITY; static SDL_LogPriority SDL_forced_priority_level;
static SDL_LogPriority SDL_application_priority = DEFAULT_APPLICATION_PRIORITY;
static SDL_LogPriority SDL_test_priority = DEFAULT_TEST_PRIORITY;
static SDL_LogOutputFunction SDL_log_function = SDL_LogOutput; static SDL_LogOutputFunction SDL_log_function = SDL_LogOutput;
static void *SDL_log_userdata = NULL; static void *SDL_log_userdata = NULL;
static SDL_Mutex *log_function_mutex = NULL; static SDL_Mutex *log_function_mutex = NULL;
@ -134,9 +127,9 @@ void SDL_LogSetAllPriority(SDL_LogPriority priority)
for (entry = SDL_loglevels; entry; entry = entry->next) { for (entry = SDL_loglevels; entry; entry = entry->next) {
entry->priority = priority; entry->priority = priority;
} }
SDL_default_priority = priority;
SDL_assert_priority = priority; SDL_forced_priority = SDL_TRUE;
SDL_application_priority = priority; SDL_forced_priority_level = priority;
} }
void SDL_LogSetPriority(int category, SDL_LogPriority priority) void SDL_LogSetPriority(int category, SDL_LogPriority priority)
@ -170,14 +163,19 @@ SDL_LogPriority SDL_LogGetPriority(int category)
} }
} }
if (category == SDL_LOG_CATEGORY_TEST) { if (SDL_forced_priority) {
return SDL_test_priority; return SDL_forced_priority_level;
} else if (category == SDL_LOG_CATEGORY_APPLICATION) { }
return SDL_application_priority;
} else if (category == SDL_LOG_CATEGORY_ASSERT) { switch (category) {
return SDL_assert_priority; case SDL_LOG_CATEGORY_APPLICATION:
} else { return SDL_LOG_PRIORITY_INFO;
return SDL_default_priority; case SDL_LOG_CATEGORY_ASSERT:
return SDL_LOG_PRIORITY_WARN;
case SDL_LOG_CATEGORY_TEST:
return SDL_LOG_PRIORITY_VERBOSE;
default:
return SDL_LOG_PRIORITY_ERROR;
} }
} }
@ -190,11 +188,7 @@ void SDL_LogResetPriorities(void)
SDL_loglevels = entry->next; SDL_loglevels = entry->next;
SDL_free(entry); SDL_free(entry);
} }
SDL_forced_priority = SDL_FALSE;
SDL_default_priority = DEFAULT_PRIORITY;
SDL_assert_priority = DEFAULT_ASSERT_PRIORITY;
SDL_application_priority = DEFAULT_APPLICATION_PRIORITY;
SDL_test_priority = DEFAULT_TEST_PRIORITY;
} }
void SDL_Log(SDL_PRINTF_FORMAT_STRING const char *fmt, ...) void SDL_Log(SDL_PRINTF_FORMAT_STRING const char *fmt, ...)