Complete.Org: Mailing Lists: Archives: freeciv-dev: September 2004:
[Freeciv-Dev] Re: (PR#10234) freelog callback when writing to file
Home

[Freeciv-Dev] Re: (PR#10234) freelog callback when writing to file

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: undisclosed-recipients: ;
Subject: [Freeciv-Dev] Re: (PR#10234) freelog callback when writing to file
From: "Marko Lindqvist" <marko.lindqvist@xxxxxxxxxxx>
Date: Tue, 21 Sep 2004 08:53:47 -0700
Reply-to: rt@xxxxxxxxxxx

<URL: http://rt.freeciv.org/Ticket/Display.html?id=10234 >

Marko Lindqvist wrote:

>   Attached patch


  - Caz


diff -Nurd -X.diff_ignore freeciv/client/gui-gtk-2.0/gui_main.c 
freeciv/client/gui-gtk-2.0/gui_main.c
--- freeciv/client/gui-gtk-2.0/gui_main.c       2004-09-20 23:48:11.141821900 
+0300
+++ freeciv/client/gui-gtk-2.0/gui_main.c       2004-09-21 18:02:06.484375000 
+0300
@@ -179,9 +179,11 @@
 /**************************************************************************
 ...
 **************************************************************************/
-static void log_callback_utf8(int level, const char *message)
+static void log_callback_utf8(int level, const char *message, bool file_too)
 {
-  fc_fprintf(stderr, "%d: %s\n", level, message);
+  if (! file_too || level <= LOG_FATAL) {
+    fc_fprintf(stderr, "%d: %s\n", level, message);
+  }
 }
 
 /**************************************************************************
diff -Nurd -X.diff_ignore freeciv/server/console.c freeciv/server/console.c
--- freeciv/server/console.c    2004-09-20 23:48:53.048071900 +0300
+++ freeciv/server/console.c    2004-09-21 18:12:27.984375000 +0300
@@ -44,12 +44,16 @@
 Function to handle log messages.
 This must match the log_callback_fn typedef signature.
 ************************************************************************/
-static void con_handle_log(int level, const char *message)
+static void con_handle_log(int level, const char *message, bool file_too)
 {
-  if(console_rfcstyle) {
-    con_write(C_LOG_BASE+level, "%s", message);
-  } else {
-    con_write(C_LOG_BASE+level, "%d: %s", level, message);
+  /* Write to console only when not written to file.
+     LOG_FATAL messages always to console too. */
+  if (! file_too || level <= LOG_FATAL) {
+    if (console_rfcstyle) {
+      con_write(C_LOG_BASE + level, "%s", message);
+    } else {
+      con_write(C_LOG_BASE + level, "%d: %s", level, message);
+    }
   }
 }
 
@@ -80,9 +84,7 @@
 ************************************************************************/
 void con_log_init(const char *log_filename, int log_level)
 {
-  bool has_file = (log_filename && strlen(log_filename) > 0);
-
-  log_init(log_filename, log_level, has_file ? NULL : con_handle_log);
+  log_init(log_filename, log_level, con_handle_log);
 }
 
 #ifndef HAVE_LIBREADLINE
diff -Nurd -X.diff_ignore freeciv/utility/log.c freeciv/utility/log.c
--- freeciv/utility/log.c       2004-09-20 23:48:58.610571900 +0300
+++ freeciv/utility/log.c       2004-09-21 17:54:30.437500000 +0300
@@ -234,15 +234,15 @@
 Unconditionally print a simple string.
 Let the callback do its own level formating and add a '\n' if it wants.
 **************************************************************************/
-static void log_write(FILE *fs, int level, char *message)
+static void log_write(FILE *fs, int level, const char *message)
 {
-  if ((!log_filename) && log_callback) {
-    log_callback(level, message);
-  }
   if (log_filename || (!log_callback)) {
     fc_fprintf(fs, "%d: %s\n", level, message);
     fflush(fs);
   }
+  if (log_callback) {
+    log_callback(level, message, log_filename != NULL);
+  }
 }
 
 /**************************************************************************
diff -Nurd -X.diff_ignore freeciv/utility/log.h freeciv/utility/log.h
--- freeciv/utility/log.h       2004-09-20 23:48:58.641821900 +0300
+++ freeciv/utility/log.h       2004-09-21 17:54:31.671875000 +0300
@@ -49,7 +49,7 @@
  * via fputs(stderr).  Eg, to the server console while handling prompts,
  * rfcstyle, client notifications; Eg, to the client window output window?
  */
-typedef void (*log_callback_fn)(int, const char*);
+typedef void (*log_callback_fn)(int, const char*, bool file_too);
 
 int log_parse_level_str(const char *level_str);
 void log_init(const char *filename, int initial_level,

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] Re: (PR#10234) freelog callback when writing to file, Marko Lindqvist <=