SDLInputSource: Add log callback

This commit is contained in:
Stenzek 2023-11-06 19:31:20 +10:00
parent 536f1511c2
commit a4127aa2ea
No known key found for this signature in database
1 changed files with 22 additions and 0 deletions

View File

@ -104,6 +104,21 @@ static void SetControllerRGBLED(SDL_GameController* gc, u32 color)
SDL_GameControllerSetLED(gc, (color >> 16) & 0xff, (color >> 8) & 0xff, color & 0xff);
}
static void SDLLogCallback(void* userdata, int category, SDL_LogPriority priority, const char* message)
{
static constexpr LOGLEVEL priority_map[SDL_NUM_LOG_PRIORITIES] = {
LOGLEVEL_DEBUG,
LOGLEVEL_DEBUG, // SDL_LOG_PRIORITY_VERBOSE
LOGLEVEL_DEBUG, // SDL_LOG_PRIORITY_DEBUG
LOGLEVEL_INFO, // SDL_LOG_PRIORITY_INFO
LOGLEVEL_WARNING, // SDL_LOG_PRIORITY_WARN
LOGLEVEL_ERROR, // SDL_LOG_PRIORITY_ERROR
LOGLEVEL_ERROR, // SDL_LOG_PRIORITY_CRITICAL
};
Log::Write("SDL", "SDL", priority_map[priority], message);
}
SDLInputSource::SDLInputSource() = default;
SDLInputSource::~SDLInputSource()
@ -226,6 +241,13 @@ bool SDLInputSource::InitializeSubsystem()
return false;
}
SDL_LogSetOutputFunction(SDLLogCallback, nullptr);
#ifdef _DEBUG
SDL_LogSetAllPriority(SDL_LOG_PRIORITY_VERBOSE);
#else
SDL_LogSetAllPriority(SDL_LOG_PRIORITY_INFO);
#endif
// we should open the controllers as the connected events come in, so no need to do any more here
m_sdl_subsystem_initialized = true;
return true;