diff options
author | Andrei Karas <akaras@inbox.ru> | 2017-09-11 19:58:07 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2017-09-11 23:36:49 +0300 |
commit | b6bf8e607146202b82b7943147fc5a99d4c46a60 (patch) | |
tree | 0465526af0ebefee944382af2869f08bfbcc7c94 | |
parent | dbf65ef9c85f1b1b93fc9666bda31c5e5171b8c7 (diff) | |
download | plus-b6bf8e607146202b82b7943147fc5a99d4c46a60.tar.gz plus-b6bf8e607146202b82b7943147fc5a99d4c46a60.tar.bz2 plus-b6bf8e607146202b82b7943147fc5a99d4c46a60.tar.xz plus-b6bf8e607146202b82b7943147fc5a99d4c46a60.zip |
Add option to set sdl logging level.
Only for SDL2.
-rw-r--r-- | src/defaults.cpp | 1 | ||||
-rw-r--r-- | src/gui/widgets/tabs/setup_misc.cpp | 85 | ||||
-rw-r--r-- | src/gui/widgets/tabs/setup_misc.h | 3 | ||||
-rw-r--r-- | src/progs/dyecmd/client.cpp | 1 | ||||
-rw-r--r-- | src/progs/manaplus/client.cpp | 1 | ||||
-rw-r--r-- | src/utils/sdl2helper.cpp | 5 | ||||
-rw-r--r-- | src/utils/sdl2helper.h | 2 | ||||
-rw-r--r-- | src/utils/sdl2logger.cpp | 15 | ||||
-rw-r--r-- | src/utils/sdl2logger.h | 2 | ||||
-rw-r--r-- | src/utils/sdlhelper.cpp | 4 | ||||
-rw-r--r-- | src/utils/sdlhelper.h | 2 |
11 files changed, 98 insertions, 23 deletions
diff --git a/src/defaults.cpp b/src/defaults.cpp index 5df7ab80e..4406b7c40 100644 --- a/src/defaults.cpp +++ b/src/defaults.cpp @@ -310,6 +310,7 @@ void setConfigDefaults(Configuration &cfg) AddDEF("repeateDelay", 500); AddDEF("repeateInterval", 30); AddDEF("repeateInterval2", 500); + AddDEF("sdlLogLevel", 0); #else // USE_SDL2 AddDEF("repeateDelay", SDL_DEFAULT_REPEAT_DELAY); diff --git a/src/gui/widgets/tabs/setup_misc.cpp b/src/gui/widgets/tabs/setup_misc.cpp index 759f6507e..f4ce6cba0 100644 --- a/src/gui/widgets/tabs/setup_misc.cpp +++ b/src/gui/widgets/tabs/setup_misc.cpp @@ -91,10 +91,35 @@ static const char *const densityList[] = N_("xxhigh") }; +#ifdef USE_SDL2 +static const int sdlLogListSize = 7; + +static const char *const sdlLogList[] = +{ + // TRANSLATORS: sdl2 log level + N_("default"), + // TRANSLATORS: sdl2 log level + N_("verbose"), + // TRANSLATORS: sdl2 log level + N_("debug"), + // TRANSLATORS: sdl2 log level + N_("info"), + // TRANSLATORS: sdl2 log level + N_("warn"), + // TRANSLATORS: sdl2 log level + N_("error"), + // TRANSLATORS: sdl2 log level + N_("critical") +}; +#endif // USE_SDL2 + Setup_Misc::Setup_Misc(const Widget2 *const widget) : SetupTabScroll(widget), mProxyTypeList(new NamesModel), mShortcutsList(new NamesModel), +#ifdef USE_SDL2 + mSdlLogList(new NamesModel), +#endif // USE_SDL2 mDensityList(new NamesModel) { // TRANSLATORS: misc tab in settings @@ -362,29 +387,7 @@ Setup_Misc::Setup_Misc(const Widget2 *const widget) : // TRANSLATORS: settings group - new SetupItemLabel(_("Other"), "", this); - - // TRANSLATORS: settings option - new SetupItemCheckBox(_("Enable server side attack"), "", - "serverAttack", this, "serverAttackEvent"); - - // TRANSLATORS: settings option - new SetupItemCheckBox(_("Hide support page link on error"), "", - "hidesupport", this, "hidesupportEvent"); - - // TRANSLATORS: settings option - new SetupItemCheckBox(_("Enable double clicks"), "", - "doubleClick", this, "doubleClickEvent"); - - // TRANSLATORS: settings option - new SetupItemCheckBox(_("Enable bot checker"), "", - "enableBotCheker", this, "enableBotChekerEvent"); - - // TRANSLATORS: settings option - new SetupItemCheckBox(_("Enable buggy servers protection " - "(do not disable)"), "", "enableBuggyServers", this, - "enableBuggyServersEvent", - MainConfig_false); + new SetupItemLabel(_("Logging"), "", this); // TRANSLATORS: settings option new SetupItemCheckBox(_("Enable OpenGL version check " @@ -411,10 +414,43 @@ Setup_Misc::Setup_Misc(const Widget2 *const widget) : new SetupItemCheckBox(_("Enable input log"), "", "logInput", this, "logInputEvent"); +#ifdef USE_SDL2 + mSdlLogList->fillFromArray(&sdlLogList[0], sdlLogListSize); + // TRANSLATORS: settings option + new SetupItemDropDown(_("SDL logging level"), "", + "sdlLogLevel", this, "sdlLogLevelEvent", mSdlLogList, 100); +#endif // USE_SDL2 + // TRANSLATORS: settings option new SetupButtonItem(_("Upload log file"), "", "upload", this, "uploadLog", &uploadListener); + + // TRANSLATORS: settings group + new SetupItemLabel(_("Other"), "", this); + + // TRANSLATORS: settings option + new SetupItemCheckBox(_("Enable server side attack"), "", + "serverAttack", this, "serverAttackEvent"); + + // TRANSLATORS: settings option + new SetupItemCheckBox(_("Hide support page link on error"), "", + "hidesupport", this, "hidesupportEvent"); + + // TRANSLATORS: settings option + new SetupItemCheckBox(_("Enable double clicks"), "", + "doubleClick", this, "doubleClickEvent"); + + // TRANSLATORS: settings option + new SetupItemCheckBox(_("Enable bot checker"), "", + "enableBotCheker", this, "enableBotChekerEvent"); + + // TRANSLATORS: settings option + new SetupItemCheckBox(_("Enable buggy servers protection " + "(do not disable)"), "", "enableBuggyServers", this, + "enableBuggyServersEvent", + MainConfig_false); + // TRANSLATORS: settings option new SetupItemCheckBox(_("Low traffic mode"), "", "lowTraffic", this, "lowTrafficEvent"); @@ -454,6 +490,9 @@ Setup_Misc::~Setup_Misc() delete2(mProxyTypeList); delete2(mShortcutsList); delete2(mDensityList); +#ifdef USE_SDL2 + delete2(mSdlLogList); +#endif // USE_SDL2 } void Setup_Misc::apply() diff --git a/src/gui/widgets/tabs/setup_misc.h b/src/gui/widgets/tabs/setup_misc.h index c31026c92..787f4c181 100644 --- a/src/gui/widgets/tabs/setup_misc.h +++ b/src/gui/widgets/tabs/setup_misc.h @@ -43,6 +43,9 @@ class Setup_Misc final : public SetupTabScroll protected: NamesModel *mProxyTypeList; NamesModel *mShortcutsList; +#ifdef USE_SDL2 + NamesModel *mSdlLogList; +#endif // USE_SDL2 NamesModel *mDensityList; }; diff --git a/src/progs/dyecmd/client.cpp b/src/progs/dyecmd/client.cpp index ccc8a51af..41bb7f3cb 100644 --- a/src/progs/dyecmd/client.cpp +++ b/src/progs/dyecmd/client.cpp @@ -188,6 +188,7 @@ void Client::gameInit() if (settings.options.test.empty()) ConfigManager::backupConfig("config.xml"); ConfigManager::initConfiguration(); + SDL::setLogLevel(config.getIntValue("sdlLogLevel")); setPathsDefaults(paths); initPaths(); logger->log("init 4"); diff --git a/src/progs/manaplus/client.cpp b/src/progs/manaplus/client.cpp index af46d8683..a9735f43e 100644 --- a/src/progs/manaplus/client.cpp +++ b/src/progs/manaplus/client.cpp @@ -310,6 +310,7 @@ void Client::gameInit() if (settings.options.test.empty()) ConfigManager::backupConfig("config.xml"); ConfigManager::initConfiguration(); + SDL::setLogLevel(config.getIntValue("sdlLogLevel")); settings.init(); Net::loadIgnorePackets(); setPathsDefaults(paths); 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<SDL_LogPriority>(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); |