Author: cazfi
Date: Mon Apr  4 05:37:27 2016
New Revision: 32300

URL: http://svn.gna.org/viewcvs/freeciv?rev=32300&view=rev
Log:
Pass log level parameter to client spawned server.

Requested by Christian Knoke <chrisk>

See bug #21540

Modified:
    trunk/client/connectdlg_common.c
    trunk/utility/log.c
    trunk/utility/log.h

Modified: trunk/client/connectdlg_common.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/connectdlg_common.c?rev=32300&r1=32299&r2=32300&view=diff
==============================================================================
--- trunk/client/connectdlg_common.c    (original)
+++ trunk/client/connectdlg_common.c    Mon Apr  4 05:37:27 2016
@@ -1,4 +1,4 @@
-/********************************************************************** 
+/**********************************************************************
 Freeciv - Copyright (C) 2004 - The Freeciv Project
    This program is free software; you can redistribute it and / or modify
    it under the terms of the GNU General Public License as published by
@@ -90,11 +90,11 @@
 
 Two distinct paths are taken depending on the choice of mode: 
 
-if the user selects the multi- player mode, then a packet_req_join_game 
+if the user selects the multi- player mode, then a packet_req_join_game
 packet is sent to the server. It is either successful or not. The end.
 
-If the user selects a single- player mode (either a new game or a save game) 
-then: 
+If the user selects a single- player mode (either a new game or a save game)
+then:
    1. the packet_req_join_game is sent.
    2. on receipt, if we can join, then a challenge packet is sent to the
       server, so we can get hack level control.
@@ -102,17 +102,17 @@
       we can, then:
       a. for a new game, we send a series of packet_generic_message packets
          with commands to start the game.
-      b. for a saved game, we send the load command with a 
+      b. for a saved game, we send the load command with a
          packet_generic_message, then we send a PACKET_PLAYER_LIST_REQUEST.
          the response to this request will tell us if the game was loaded or
          not. if not, then we send another load command. if so, then we send
-         a series of packet_generic_message packets with commands to start 
+         a series of packet_generic_message packets with commands to start
          the game.
-**************************************************************************/ 
-
-/************************************************************************** 
-Tests if the client has started the server.
-**************************************************************************/ 
+**************************************************************************/
+
+/**************************************************************************
+  Tests if the client has started the server.
+**************************************************************************/
 bool is_server_running(void)
 {
 #ifdef HAVE_USABLE_FORK
@@ -122,9 +122,9 @@
 #else
   return FALSE; /* We've been unable to start one! */
 #endif
-} 
-
-/************************************************************************** 
+}
+
+/**************************************************************************
   Returns TRUE if the client has hack access.
 **************************************************************************/
 bool can_client_access_hack(void)
@@ -184,10 +184,10 @@
   client_has_hack = FALSE;
 }   
 
-/**************************************************************** 
+/****************************************************************
   Forks a server if it can. Returns FALSE if we find we
   couldn't start the server.
-*****************************************************************/ 
+*****************************************************************/
 bool client_start_server(void)
 {
 #if !defined(HAVE_USABLE_FORK) && !defined(WIN32_NATIVE)
@@ -250,7 +250,11 @@
   {
     int argc = 0;
     const int max_nargs = 23;
-    char *argv[max_nargs + 1], port_buf[32];
+    char *argv[max_nargs + 1];
+    char port_buf[32];
+    char dbg_lvl_buf[32]; /* Do not move this inside the block where it gets 
filled,
+                           * it's needed via the argv[x] pointer later on, so 
must
+                           * remain in scope. */
 
     /* Set up the command-line parameters. */
     fc_snprintf(port_buf, sizeof(port_buf), "%d", internal_server_port);
@@ -269,8 +273,11 @@
     argv[argc++] = "-A";
     argv[argc++] = "none";
     if (logfile) {
+      enum log_level llvl = log_get_level();
+
       argv[argc++] = "--debug";
-      argv[argc++] = "3";
+      fc_snprintf(dbg_lvl_buf, sizeof(dbg_lvl_buf), "%d", llvl);
+      argv[argc++] = dbg_lvl_buf;
       argv[argc++] = "--log";
       argv[argc++] = logfile;
     }
@@ -374,8 +381,9 @@
   if (logfile) {
     char *logfile_in_local_encoding =
         internal_to_local_string_malloc(logfile);
-
-    fc_snprintf(logcmdline, sizeof(logcmdline), " --debug 3 --log %s",
+    enum log_level llvl = log_get_level();
+
+    fc_snprintf(logcmdline, sizeof(logcmdline), " --debug %d --log %s", llvl,
                 logfile_in_local_encoding);
     free(logfile_in_local_encoding);
   }

Modified: trunk/utility/log.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/utility/log.c?rev=32300&r1=32299&r2=32300&view=diff
==============================================================================
--- trunk/utility/log.c (original)
+++ trunk/utility/log.c Mon Apr  4 05:37:27 2016
@@ -317,6 +317,18 @@
 enum log_level log_get_level(void)
 {
   return fc_log_level;
+}
+
+/**************************************************************************
+  Return name of the given log level
+**************************************************************************/
+const char *log_level_name(enum log_level lvl)
+{
+  if (lvl < LOG_FATAL || lvl > LOG_DEBUG) {
+    return NULL;
+  }
+
+  return log_level_names[lvl];
 }
 
 #ifdef DEBUG

Modified: trunk/utility/log.h
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/utility/log.h?rev=32300&r1=32299&r2=32300&view=diff
==============================================================================
--- trunk/utility/log.h (original)
+++ trunk/utility/log.h Mon Apr  4 05:37:27 2016
@@ -64,6 +64,7 @@
 log_prefix_fn log_set_prefix(log_prefix_fn prefix);
 void log_set_level(enum log_level level);
 enum log_level log_get_level(void);
+const char *log_level_name(enum log_level lvl);
 #ifdef FREECIV_DEBUG
 bool log_do_output_for_level_at_location(enum log_level level,
                                          const char *file, int line);


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

Reply via email to