How are log category priorities supposed to behave?

SDL_LOG_PRIORITY_CRITICAL seems to be the highest log-priority, but log categories with this priority aren’t displayed unless the log priority is also critical. This seems unintuitive, so much that it seems like a bug? Like, shouldn’t critical log messages always be displayed no matter the priority level?

I was taking a look at the source code, in particular on line 315 of SDL_Log.c in SDL_LogMessageV

/* See if we want to do anything with this message */
if (priority < SDL_LogGetPriority(category)) {
    return;
}

This prevents message categories with a higher priority than what was given from being displayed. For example,

SDL_LogError(SDL_LOG_CATEGORY_SYSTEM,...);

won’t actually log anything because SDL_LOG_CATEGORY_SYSTEM has SDL_LOG_PRIORITY_CRITICAL and SDL_LOG_PRIORITY_CRITICAL > SDL_LOG_PRIORITY_ERROR.

Maybe I’m thinking about this wrong, but wouldn’t we want to prevent message categories with a lower priority than what was given from being displayed? This would be a pretty simple change

/* Prevent message categories with a lower priority. */
if (SDL_LogGetPriority(category) < priority) {
    return;
}
1 Like