Author: jtn
Date: Wed Mar 16 01:36:59 2016
New Revision: 32249

URL: http://svn.gna.org/viewcvs/freeciv?rev=32249&view=rev
Log:
Add '-d' option to modpack installers to set log level.
Log messages from netfile, etc, as LOG_VERBOSE as well as briefly
showing them on the status bar.

See gna patch #7060.

Modified:
    trunk/tools/modinst.c
    trunk/tools/modinst.h
    trunk/tools/mpcli.c
    trunk/tools/mpcmdline.c
    trunk/tools/mpgui_gtk2.c
    trunk/tools/mpgui_gtk3.c
    trunk/tools/mpgui_qt.cpp

Modified: trunk/tools/modinst.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/tools/modinst.c?rev=32249&r1=32248&r2=32249&view=diff
==============================================================================
--- trunk/tools/modinst.c       (original)
+++ trunk/tools/modinst.c       Wed Mar 16 01:36:59 2016
@@ -175,7 +175,7 @@
 /**************************************************************************
   Initialize modpack installer
 **************************************************************************/
-void fcmp_init(int loglevel)
+void fcmp_init(void)
 {
   init_nls();
   init_character_encodings(FC_DEFAULT_DATA_ENCODING, FALSE);
@@ -183,7 +183,6 @@
 
   fc_init_network();
 
-  log_init(NULL, loglevel, NULL, NULL, -1);
   fc_srand(time(NULL)); /* Needed at least for Windows version of 
netfile_get_section_file() */
 }
 
@@ -194,6 +193,8 @@
 {
   registry_module_close();
   fc_shutdown_network();
+  /* log_init() was not done by fcmp_init(); we assume the caller called
+   * fcmp_parse_cmdline() (which sets up logging) in between */
   log_close();
   free_libfreeciv();
   free_nls();

Modified: trunk/tools/modinst.h
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/tools/modinst.h?rev=32249&r1=32248&r2=32249&view=diff
==============================================================================
--- trunk/tools/modinst.h       (original)
+++ trunk/tools/modinst.h       Wed Mar 16 01:36:59 2016
@@ -51,7 +51,7 @@
 #define SPECENUM_VALUE6NAME N_("Group")
 #include "specenum_gen.h"
 
-void fcmp_init(int loglevel);
+void fcmp_init(void);
 void fcmp_deinit(void);
 
 void load_install_info_lists(struct fcmp_params *fcmp);

Modified: trunk/tools/mpcli.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/tools/mpcli.c?rev=32249&r1=32248&r2=32249&view=diff
==============================================================================
--- trunk/tools/mpcli.c (original)
+++ trunk/tools/mpcli.c Wed Mar 16 01:36:59 2016
@@ -96,10 +96,9 @@
 **************************************************************************/
 int main(int argc, char *argv[])
 {
-  int loglevel = LOG_NORMAL;
   int ui_options;
 
-  fcmp_init(loglevel);
+  fcmp_init();
 
   /* This modifies argv! */
   ui_options = fcmp_parse_cmdline(argc, argv);

Modified: trunk/tools/mpcmdline.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/tools/mpcmdline.c?rev=32249&r1=32248&r2=32249&view=diff
==============================================================================
--- trunk/tools/mpcmdline.c     (original)
+++ trunk/tools/mpcmdline.c     Wed Mar 16 01:36:59 2016
@@ -40,6 +40,7 @@
   returns with success or exit()s. Implementation can be changed so that
   this returns with value -1 in case program should be shut down instead
   of exiting itself. Callers are prepared for such implementation.
+  This call initialises the log system.
 **************************************************************************/
 int fcmp_parse_cmdline(int argc, char *argv[])
 {
@@ -47,6 +48,7 @@
   bool ui_separator = FALSE;
   int ui_options = 0;
   const char *option = NULL;
+  enum log_level loglevel = LOG_NORMAL;
 
   while (i < argc) {
     if (ui_separator) {
@@ -69,6 +71,20 @@
                   /* TRANS: "install" is exactly what user must type, do not 
translate. */
                   _("install URL"),
                   _("Automatically install modpack from a given URL"));
+#ifdef FREECIV_DEBUG
+      cmdhelp_add(help, "d",
+                  /* TRANS: "debug" is exactly what user must type, do not 
translate. */
+                  _("debug NUM"),
+                  _("Set debug log level (%d to %d, or "
+                    "%d:file1,min,max:...)"), LOG_FATAL, LOG_DEBUG,
+                  LOG_DEBUG);
+#else  /* FREECIV_DEBUG */
+      cmdhelp_add(help, "d",
+                  /* TRANS: "debug" is exactly what user must type, do not 
translate. */
+                  _("debug NUM"),
+                  _("Set debug log level (%d to %d)"),
+                  LOG_FATAL, LOG_VERBOSE);
+#endif /* FREECIV_DEBUG */
       cmdhelp_add(help, "v", "version",
                   _("Print the version number"));
       /* The function below prints a header and footer for the options.
@@ -83,6 +99,14 @@
       fcmp.inst_prefix = option;
     } else if ((option = get_option_malloc("--install", argv, &i, argc))) {
       fcmp.autoinstall = option;
+    } else if ((option = get_option_malloc("--debug", argv, &i, argc))) {
+      if (!log_parse_level_str(option, &loglevel)) {
+        fc_fprintf(stderr,
+                   _("Invalid debug level \"%s\" specified with --debug "
+                     "option.\n"), option);
+        fc_fprintf(stderr, _("Try using --help.\n"));
+        exit(EXIT_FAILURE);
+      }
     } else if (is_option("--version", argv[i])) {
       fc_fprintf(stderr, "%s \n", freeciv_name_version());
 
@@ -97,6 +121,8 @@
     i++;
   }
 
+  log_init(NULL, loglevel, NULL, NULL, -1);
+
   if (fcmp.inst_prefix == NULL) {
     fcmp.inst_prefix = freeciv_storage_dir();
 

Modified: trunk/tools/mpgui_gtk2.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/tools/mpgui_gtk2.c?rev=32249&r1=32248&r2=32249&view=diff
==============================================================================
--- trunk/tools/mpgui_gtk2.c    (original)
+++ trunk/tools/mpgui_gtk2.c    Wed Mar 16 01:36:59 2016
@@ -130,6 +130,7 @@
 **************************************************************************/
 static void msg_callback(const char *msg)
 {
+  log_verbose("%s", msg);
   gtk_label_set_text(GTK_LABEL(statusbar), msg);
 }
 
@@ -558,10 +559,9 @@
 int main(int argc, char *argv[])
 {
   GtkWidget *toplevel;
-  int loglevel = LOG_NORMAL;
   int ui_options;
 
-  fcmp_init(loglevel);
+  fcmp_init();
 
   g_thread_init(NULL);
 

Modified: trunk/tools/mpgui_gtk3.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/tools/mpgui_gtk3.c?rev=32249&r1=32248&r2=32249&view=diff
==============================================================================
--- trunk/tools/mpgui_gtk3.c    (original)
+++ trunk/tools/mpgui_gtk3.c    Wed Mar 16 01:36:59 2016
@@ -130,6 +130,7 @@
 **************************************************************************/
 static void msg_callback(const char *msg)
 {
+  log_verbose("%s", msg);
   gtk_label_set_text(GTK_LABEL(statusbar), msg);
 }
 
@@ -566,10 +567,9 @@
 int main(int argc, char *argv[])
 {
   GtkWidget *toplevel;
-  int loglevel = LOG_NORMAL;
   int ui_options;
 
-  fcmp_init(loglevel);
+  fcmp_init();
 
   /* This modifies argv! */
   ui_options = fcmp_parse_cmdline(argc, argv);

Modified: trunk/tools/mpgui_qt.cpp
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/tools/mpgui_qt.cpp?rev=32249&r1=32248&r2=32249&view=diff
==============================================================================
--- trunk/tools/mpgui_qt.cpp    (original)
+++ trunk/tools/mpgui_qt.cpp    Wed Mar 16 01:36:59 2016
@@ -81,10 +81,9 @@
 **************************************************************************/
 int main(int argc, char **argv)
 {
-  enum log_level loglevel = LOG_NORMAL;
   int ui_options;
 
-  fcmp_init(loglevel);
+  fcmp_init();
 
   /* This modifies argv! */
   ui_options = fcmp_parse_cmdline(argc, argv);
@@ -271,6 +270,7 @@
 **************************************************************************/
 void mpgui::display_msg(const char *msg)
 {
+  log_verbose("%s", msg);
   msg_dspl->setText(QString::fromUtf8(msg));
 }
 


_______________________________________________
Freeciv-commits mailing list
Freeciv-commits@gna.org
https://mail.gna.org/listinfo/freeciv-commits

Reply via email to