From b6bf8e607146202b82b7943147fc5a99d4c46a60 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Mon, 11 Sep 2017 19:58:07 +0300 Subject: Add option to set sdl logging level. Only for SDL2. --- src/utils/sdl2helper.cpp | 5 +++++ src/utils/sdl2helper.h | 2 ++ src/utils/sdl2logger.cpp | 15 +++++++++++++++ src/utils/sdl2logger.h | 2 ++ src/utils/sdlhelper.cpp | 4 ++++ src/utils/sdlhelper.h | 2 ++ 6 files changed, 30 insertions(+) (limited to 'src/utils') diff --git a/src/utils/sdl2helper.cpp b/src/utils/sdl2helper.cpp index da5b15e41..00893ce82 100644 --- a/src/utils/sdl2helper.cpp +++ b/src/utils/sdl2helper.cpp @@ -189,6 +189,11 @@ void SDL::initLogger() SDL2Logger::init(); } +void SDL::setLogLevel(const int level) +{ + SDL2Logger::setLogLevel(level); +} + void SDL::WaitThread(SDL_Thread *const thread) { if (thread != nullptr) diff --git a/src/utils/sdl2helper.h b/src/utils/sdl2helper.h index d1b474d50..55d69a75d 100644 --- a/src/utils/sdl2helper.h +++ b/src/utils/sdl2helper.h @@ -66,6 +66,8 @@ namespace SDL void initLogger(); + void setLogLevel(const int level); + void WaitThread(SDL_Thread *const thread); bool PollEvent(SDL_Event *event); diff --git a/src/utils/sdl2logger.cpp b/src/utils/sdl2logger.cpp index 7f7813521..98c7d8338 100644 --- a/src/utils/sdl2logger.cpp +++ b/src/utils/sdl2logger.cpp @@ -134,8 +134,23 @@ static SDL_AssertState assertCallback(const SDL_AssertData *data, void SDL2Logger::init() { +#ifdef UNITTESTS + SDL_LogSetAllPriority(SDL_LOG_PRIORITY_WARN); +#else // UNITTESTS + + SDL_LogSetAllPriority(SDL_LOG_PRIORITY_VERBOSE); +#endif // UNITTESTS + SDL_LogSetOutputFunction(&logCallback, nullptr); SDL_SetAssertionHandler(&assertCallback, nullptr); } +void SDL2Logger::setLogLevel(const int level) +{ + if (level > 0) + SDL_LogSetAllPriority(static_cast(level)); + else + SDL_LogResetPriorities(); +} + #endif // USE_SDL2 diff --git a/src/utils/sdl2logger.h b/src/utils/sdl2logger.h index 78d94ca27..c3ecd1ada 100644 --- a/src/utils/sdl2logger.h +++ b/src/utils/sdl2logger.h @@ -28,6 +28,8 @@ namespace SDL2Logger { void init(); + + void setLogLevel(const int level); } // namespace SDL2Logger #endif // USE_SDL2 diff --git a/src/utils/sdlhelper.cpp b/src/utils/sdlhelper.cpp index 5a735b5ba..85606f7f7 100644 --- a/src/utils/sdlhelper.cpp +++ b/src/utils/sdlhelper.cpp @@ -186,6 +186,10 @@ void SDL::initLogger() { } +void SDL::setLogLevel(const int level A_UNUSED) +{ +} + void SDL::WaitThread(SDL_Thread *const thread) { if (thread != nullptr && SDL_GetThreadID(thread) != 0u) diff --git a/src/utils/sdlhelper.h b/src/utils/sdlhelper.h index 67a979da3..d388fe7fb 100644 --- a/src/utils/sdlhelper.h +++ b/src/utils/sdlhelper.h @@ -72,6 +72,8 @@ namespace SDL void initLogger(); + void setLogLevel(const int level); + void WaitThread(SDL_Thread *const thread); bool PollEvent(SDL_Event *event); -- cgit v1.2.3-60-g2f50