From 0782e877a91621b66e983280558697520dfa6394 Mon Sep 17 00:00:00 2001 From: ehofman Date: Sat, 22 Mar 2003 10:38:15 +0000 Subject: [PATCH] Add runtime log level support --- src/Main/fg_commands.cxx | 13 +++++++++++++ src/Main/main.cxx | 5 ++++- src/Main/options.cxx | 14 ++++++++++++++ 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/src/Main/fg_commands.cxx b/src/Main/fg_commands.cxx index 7d9958481..f96948796 100644 --- a/src/Main/fg_commands.cxx +++ b/src/Main/fg_commands.cxx @@ -786,6 +786,18 @@ do_presets_commit (const SGPropertyNode * arg) return true; } +/** + * Built-in command: set log level (0 ... 7) + */ +static bool +do_log_level (const SGPropertyNode * arg) +{ + sglog().setLogLevels( SG_ALL, (sgDebugPriority)arg->getIntValue() ); + + return true; +} + + //////////////////////////////////////////////////////////////////////// @@ -833,6 +845,7 @@ static struct { { "dialog-update", do_dialog_update }, { "dialog-apply", do_dialog_apply }, { "presets-commit", do_presets_commit }, + { "log-level", do_log_level }, { 0, 0 } // zero-terminated }; diff --git a/src/Main/main.cxx b/src/Main/main.cxx index c1047fe3e..803fc5cc4 100644 --- a/src/Main/main.cxx +++ b/src/Main/main.cxx @@ -279,6 +279,7 @@ ssgSimpleState *menus; SGTimeStamp last_time_stamp; SGTimeStamp current_time_stamp; + void fgBuildRenderStates( void ) { default_state = new ssgSimpleState; default_state->ref(); @@ -1021,6 +1022,8 @@ static void fgMainLoop( void ) { SGTime *t = globals->get_time_params(); + sglog().setLogLevels( SG_ALL, (sgDebugPriority)fgGetInt("/sim/log-level") ); + FGLocation * acmodel_location = 0; if(cur_fdm_state->getACModel() != 0) { acmodel_location = (FGLocation *) cur_fdm_state->getACModel()->get3DModel()->getFGLocation(); @@ -1525,7 +1528,7 @@ static bool fgMainInit( int argc, char **argv ) { #endif // set default log levels - sglog().setLogLevels( SG_ALL, SG_INFO ); + sglog().setLogLevels( SG_ALL, SG_WARN ); string version; #ifdef FLIGHTGEAR_VERSION diff --git a/src/Main/options.cxx b/src/Main/options.cxx index e38d670fc..6fb18dd41 100644 --- a/src/Main/options.cxx +++ b/src/Main/options.cxx @@ -27,6 +27,7 @@ #include #include +#include #include // rint() #include @@ -179,6 +180,8 @@ fgSetDefaults () #else fgSetString("/sim/startup/browser-app", "webrun.bat"); #endif + fgSetInt("/sim/log-level", SG_WARN); + // Features fgSetBool("/sim/hud/visibility", false); fgSetBool("/sim/panel/visibility", true); @@ -928,6 +931,13 @@ fgOptTraceWrite( const char *arg ) return FG_OPTIONS_OK; } +static int +fgOptDebugLevel( const char *arg ) +{ + fgSetInt( "/sim/log-level", atoi( arg ) ); + return FG_OPTIONS_OK; +} + static int fgOptViewOffset( const char *arg ) { @@ -1152,6 +1162,7 @@ struct OptionDesc { #endif {"trace-read", true, OPTION_FUNC, "", false, "", fgOptTraceRead }, {"trace-write", true, OPTION_FUNC, "", false, "", fgOptTraceWrite }, + {"log-level", true, OPTION_FUNC, "", false, "", fgOptDebugLevel }, {"view-offset", true, OPTION_FUNC, "", false, "", fgOptViewOffset }, {"visibility", true, OPTION_DOUBLE, "/environment/visibility-m", false, "", 0 }, {"visibility-miles", true, OPTION_FUNC, "", false, "", fgOptVisibilityMiles }, @@ -1647,6 +1658,9 @@ parse_option (const string& arg) SG_LOG(SG_GENERAL, SG_INFO, "Tracing writes for property " << name); fgGetNode(name.c_str(), true) ->setAttribute(SGPropertyNode::TRACE_WRITE, true); + } else if ( arg.find("--log-level=") == 0) { + int level = atoi(arg.substr(14)); + sglog().setLogLevels( SG_ALL, level ); } else if ( arg.find( "--view-offset=" ) == 0 ) { // $$$ begin - added VS Renganathan, 14 Oct 2K // for multi-window outside window imagery