Skip to content

Commit

Permalink
Merge pull request #14028 from glebm/fix-log-flags-2
Browse files Browse the repository at this point in the history
Only force the log level if it set via an argv
  • Loading branch information
hrydgard authored Jan 30, 2021
2 parents c84ddaa + 892ab51 commit de02c7e
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions UI/NativeApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -560,18 +560,24 @@ void NativeInit(int argc, const char *argv[], const char *savegame_dir, const ch

// Parse command line
LogTypes::LOG_LEVELS logLevel = LogTypes::LINFO;
bool forceLogLevel = false;
const auto setLogLevel = [&logLevel, &forceLogLevel](LogTypes::LOG_LEVELS level) {
logLevel = level;
forceLogLevel = true;
};

for (int i = 1; i < argc; i++) {
if (argv[i][0] == '-') {
switch (argv[i][1]) {
case 'd':
// Enable debug logging
// Note that you must also change the max log level in Log.h.
logLevel = LogTypes::LDEBUG;
setLogLevel(LogTypes::LDEBUG);
break;
case 'v':
// Enable verbose logging
// Note that you must also change the max log level in Log.h.
logLevel = LogTypes::LVERBOSE;
setLogLevel(LogTypes::LVERBOSE);
break;
case 'j':
g_Config.iCpuCore = (int)CPUCore::JIT;
Expand All @@ -587,7 +593,7 @@ void NativeInit(int argc, const char *argv[], const char *savegame_dir, const ch
break;
case '-':
if (!strncmp(argv[i], "--loglevel=", strlen("--loglevel=")) && strlen(argv[i]) > strlen("--loglevel="))
logLevel = static_cast<LogTypes::LOG_LEVELS>(std::atoi(argv[i] + strlen("--loglevel=")));
setLogLevel(static_cast<LogTypes::LOG_LEVELS>(std::atoi(argv[i] + strlen("--loglevel="))));
if (!strncmp(argv[i], "--log=", strlen("--log=")) && strlen(argv[i]) > strlen("--log="))
fileToLog = argv[i] + strlen("--log=");
if (!strncmp(argv[i], "--state=", strlen("--state=")) && strlen(argv[i]) > strlen("--state="))
Expand Down Expand Up @@ -668,7 +674,8 @@ void NativeInit(int argc, const char *argv[], const char *savegame_dir, const ch
if (fileToLog)
LogManager::GetInstance()->ChangeFileLog(fileToLog);

LogManager::GetInstance()->SetAllLogLevels(logLevel);
if (forceLogLevel)
LogManager::GetInstance()->SetAllLogLevels(logLevel);

PostLoadConfig();

Expand Down

0 comments on commit de02c7e

Please sign in to comment.