Added debug log level setting
authorkwolekr <mirrorisim@gmail.com>
Sat, 9 Feb 2013 02:52:23 +0000 (21:52 -0500)
committerkwolekr <mirrorisim@gmail.com>
Fri, 22 Feb 2013 03:35:04 +0000 (22:35 -0500)
src/defaultsettings.cpp
src/main.cpp

index d3a455ccb4f7bf2a6b49550b35da67a616d44f75..6cdaaa49615afb1d28bceaf86aa93d75a90851d5 100644 (file)
@@ -183,7 +183,7 @@ void set_default_settings(Settings *settings)
        settings->setDefault("congestion_control_max_rate", "400");
        settings->setDefault("congestion_control_min_rate", "10");
        settings->setDefault("remote_media", "");
-
+       settings->setDefault("debug_log_level", "0");
        // physics stuff
        settings->setDefault("movement_acceleration_default", "3");
        settings->setDefault("movement_acceleration_air", "2");
index fd3643e60be967637eb0c0e82bc4576c5af4fc6d..9287ec760c89d2bd16a816ea9a766cc99e75958b 100644 (file)
@@ -887,22 +887,7 @@ int main(int argc, char *argv[])
        fs::CreateDir(porting::path_user);
 
        init_gettext((porting::path_share + DIR_DELIM + "locale").c_str());
-       
-       // Initialize debug streams
-#define DEBUGFILE "debug.txt"
-#if RUN_IN_PLACE
-       std::string logfile = DEBUGFILE;
-#else
-       std::string logfile = porting::path_user+DIR_DELIM+DEBUGFILE;
-#endif
-       if(cmd_args.exists("logfile"))
-               logfile = cmd_args.get("logfile");
-       if(logfile != "")
-               debugstreams_init(false, logfile.c_str());
-       else
-               debugstreams_init(false, NULL);
 
-       infostream<<"logfile    = "<<logfile<<std::endl;
        infostream<<"path_share = "<<porting::path_share<<std::endl;
        infostream<<"path_user  = "<<porting::path_user<<std::endl;
 
@@ -995,6 +980,31 @@ int main(int argc, char *argv[])
                if(configpath == "")
                        configpath = filenames[0];
        }
+       
+       // Initialize debug streams
+#define DEBUGFILE "debug.txt"
+#if RUN_IN_PLACE
+       std::string logfile = DEBUGFILE;
+#else
+       std::string logfile = porting::path_user+DIR_DELIM+DEBUGFILE;
+#endif
+       if(cmd_args.exists("logfile"))
+               logfile = cmd_args.get("logfile");
+       
+       log_remove_output(&main_dstream_no_stderr_log_out);
+       int loglevel = g_settings->getS32("debug_log_level");
+
+       if (loglevel == 0) //no logging
+               logfile = "";
+       else if (loglevel > 0 && loglevel <= LMT_NUM_VALUES)
+               log_add_output_maxlev(&main_dstream_no_stderr_log_out, (LogMessageLevel)(loglevel - 1));
+
+       if(logfile != "")
+               debugstreams_init(false, logfile.c_str());
+       else
+               debugstreams_init(false, NULL);
+               
+       infostream<<"logfile    = "<<logfile<<std::endl;
 
        // Initialize random seed
        srand(time(0));