Author: jtn Date: Wed Mar 16 01:46:53 2016 New Revision: 32251 URL: http://svn.gna.org/viewcvs/freeciv?rev=32251&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: branches/S2_6/tools/modinst.c branches/S2_6/tools/modinst.h branches/S2_6/tools/mpcli.c branches/S2_6/tools/mpcmdline.c branches/S2_6/tools/mpgui_gtk2.c branches/S2_6/tools/mpgui_gtk3.c branches/S2_6/tools/mpgui_qt.cpp Modified: branches/S2_6/tools/modinst.c URL: http://svn.gna.org/viewcvs/freeciv/branches/S2_6/tools/modinst.c?rev=32251&r1=32250&r2=32251&view=diff ============================================================================== --- branches/S2_6/tools/modinst.c (original) +++ branches/S2_6/tools/modinst.c Wed Mar 16 01:46:53 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: branches/S2_6/tools/modinst.h URL: http://svn.gna.org/viewcvs/freeciv/branches/S2_6/tools/modinst.h?rev=32251&r1=32250&r2=32251&view=diff ============================================================================== --- branches/S2_6/tools/modinst.h (original) +++ branches/S2_6/tools/modinst.h Wed Mar 16 01:46:53 2016 @@ -49,7 +49,7 @@ #define SPECENUM_VALUE5NAME N_("Musicset") #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: branches/S2_6/tools/mpcli.c URL: http://svn.gna.org/viewcvs/freeciv/branches/S2_6/tools/mpcli.c?rev=32251&r1=32250&r2=32251&view=diff ============================================================================== --- branches/S2_6/tools/mpcli.c (original) +++ branches/S2_6/tools/mpcli.c Wed Mar 16 01:46:53 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: branches/S2_6/tools/mpcmdline.c URL: http://svn.gna.org/viewcvs/freeciv/branches/S2_6/tools/mpcmdline.c?rev=32251&r1=32250&r2=32251&view=diff ============================================================================== --- branches/S2_6/tools/mpcmdline.c (original) +++ branches/S2_6/tools/mpcmdline.c Wed Mar 16 01:46:53 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()); @@ -96,6 +120,8 @@ i++; } + + log_init(NULL, loglevel, NULL, NULL, -1); if (fcmp.inst_prefix == NULL) { const char *home = user_home_dir(); Modified: branches/S2_6/tools/mpgui_gtk2.c URL: http://svn.gna.org/viewcvs/freeciv/branches/S2_6/tools/mpgui_gtk2.c?rev=32251&r1=32250&r2=32251&view=diff ============================================================================== --- branches/S2_6/tools/mpgui_gtk2.c (original) +++ branches/S2_6/tools/mpgui_gtk2.c Wed Mar 16 01:46:53 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: branches/S2_6/tools/mpgui_gtk3.c URL: http://svn.gna.org/viewcvs/freeciv/branches/S2_6/tools/mpgui_gtk3.c?rev=32251&r1=32250&r2=32251&view=diff ============================================================================== --- branches/S2_6/tools/mpgui_gtk3.c (original) +++ branches/S2_6/tools/mpgui_gtk3.c Wed Mar 16 01:46:53 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: branches/S2_6/tools/mpgui_qt.cpp URL: http://svn.gna.org/viewcvs/freeciv/branches/S2_6/tools/mpgui_qt.cpp?rev=32251&r1=32250&r2=32251&view=diff ============================================================================== --- branches/S2_6/tools/mpgui_qt.cpp (original) +++ branches/S2_6/tools/mpgui_qt.cpp Wed Mar 16 01:46:53 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