diff --git a/src/GUI/QtLauncher.cxx b/src/GUI/QtLauncher.cxx index 733108832..7867a83d9 100644 --- a/src/GUI/QtLauncher.cxx +++ b/src/GUI/QtLauncher.cxx @@ -249,7 +249,6 @@ void initApp(int& argc, char** argv, bool doInitQSettings) if (!qtInitDone) { qtInitDone = true; - sglog().setLogLevels( SG_ALL, SG_INFO ); initQtResources(); // can't be called from a namespace s_argc = argc; // QApplication only stores a reference to argc, diff --git a/src/Main/fg_props.cxx b/src/Main/fg_props.cxx index 62906050e..ca48f5446 100644 --- a/src/Main/fg_props.cxx +++ b/src/Main/fg_props.cxx @@ -194,20 +194,18 @@ setLoggingPriority (const char * p) { if (p == 0) return; + string priority = p; - if (priority == "bulk") { - sglog().set_log_priority(SG_BULK); - } else if (priority == "debug") { - sglog().set_log_priority(SG_DEBUG); - } else if (priority.empty() || priority == "info") { // default - sglog().set_log_priority(SG_INFO); - } else if (priority == "warn") { - sglog().set_log_priority(SG_WARN); - } else if (priority == "alert") { - sglog().set_log_priority(SG_ALERT); + if (priority.empty()) { + sglog().set_log_priority(SG_INFO); } else { - SG_LOG(SG_GENERAL, SG_WARN, "Unknown logging priority " << priority); + try { + sglog().set_log_priority(logstream::priorityFromString(priority)); + } catch (std::exception& e) { + SG_LOG(SG_GENERAL, SG_WARN, "Unknown logging priority: " << priority); + } } + SG_LOG(SG_GENERAL, SG_DEBUG, "Logging priority is " << getLoggingPriority()); } diff --git a/src/Main/main.cxx b/src/Main/main.cxx index e2fb89066..67f45ee7a 100755 --- a/src/Main/main.cxx +++ b/src/Main/main.cxx @@ -506,8 +506,18 @@ extern "C" { } #endif -static void logToHome() +static void logToHome(const std::string& pri) { + sgDebugPriority fileLogLevel = SG_INFO; + // https://sourceforge.net/p/flightgear/codetickets/2100/ + if (!pri.empty()) { + try { + fileLogLevel = std::min(fileLogLevel, logstream::priorityFromString(pri)); + } catch (std::exception& e) { + // let's not worry about this, and just log at INFO + } + } + SGPath logPath = globals->get_fg_home(); logPath.append("fgfs.log"); if (logPath.exists()) { @@ -518,7 +528,8 @@ static void logToHome() logPath = globals->get_fg_home(); logPath.append("fgfs.log"); } - sglog().logToFile(logPath, SG_ALL, SG_INFO); + + sglog().logToFile(logPath, SG_ALL, fileLogLevel); } // Main top level initialization @@ -563,7 +574,8 @@ int fgMainInit( int argc, char **argv ) const bool readOnlyFGHome = fgGetBool("/sim/fghome-readonly"); if (!readOnlyFGHome) { // now home is initialised, we can log to a file inside it - logToHome(); + const auto level = flightgear::Options::getArgValue(argc, argv, "--log-level"); + logToHome(level); } if (readOnlyFGHome) {