silclog also outputs standard logging channels to stderr when
authorGiovanni Giacobbi <johnny@silcnet.org>
Sun, 10 Mar 2002 22:40:48 +0000 (22:40 +0000)
committerGiovanni Giacobbi <johnny@silcnet.org>
Sun, 10 Mar 2002 22:40:48 +0000 (22:40 +0000)
silc_debug is TRUE.  Some typo fixes in the documentation.
call silc_log_flush_all() at the end of silc_log_reset_all().
changed var new to proto_new in silcprotocol.c

CHANGES
lib/silcutil/silclog.c
lib/silcutil/silclog.h
lib/silcutil/silcprotocol.c

diff --git a/CHANGES b/CHANGES
index bc2264a7f4c4457dd75c30579cee0108322077f9..fb664a36c83306be6adf476cf180b3bfeed87c1d 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -1,3 +1,13 @@
+Sun Mar 10 23:34:48 CET 2002  Johnny Mnemonic <johnny@themnemonic.org>
+
+       * If silc_debug is TRUE, also output standard logging messages
+         to stderr with the debug output.
+
+         Made silc_log_reset_all() flushing all channels before returning.
+         Also fixed some documentation typos.
+
+         Affected files are lib/silcutil/silclog.[ch].
+
 Sun Mar 10 20:07:49 EET 2002  Pekka Riikonen <priikone@silcnet.org>
 
        * Fixed the server to check correctly the amount of connections
index b415c664d1eecc3ed45b0b6829da2895f859c206..06e5771f31f220d2eb8598314e6cd566322455d6 100644 (file)
@@ -40,7 +40,8 @@ struct SilcLogStruct {
 };
 typedef struct SilcLogStruct *SilcLog;
 
-/* These are the known logging channels */
+/* These are the known logging channels.  We initialize this struct with most
+ * of the fields set to NULL, because we'll fill in those values at runtime. */
 static struct SilcLogStruct silclogs[SILC_LOG_MAX] = {
   {NULL, NULL, 0, "Info", SILC_LOG_INFO, NULL, NULL},
   {NULL, NULL, 0, "Warning", SILC_LOG_WARNING, NULL, NULL},
@@ -55,13 +56,13 @@ bool silc_log_quick = FALSE;
 bool silc_debug = FALSE;
 bool silc_debug_hexdump = FALSE;
 
-/* Flush delay */
+/* Flush delay (in seconds) */
 long silc_log_flushdelay = 300;
 
 /* Regular pattern matching expression for the debug output */
 char *silc_log_debug_string = NULL;
 
-/* Debug callbacks. If set these are used instead of default ones. */
+/* Debug callbacks. If set, these are triggered for each specific output. */
 static SilcLogDebugCb silc_log_debug_cb = NULL;
 static void *silc_log_debug_context = NULL;
 static SilcLogHexdumpCb silc_log_hexdump_cb = NULL;
@@ -71,7 +72,7 @@ static void *silc_log_hexdump_context = NULL;
 static bool silc_log_scheduled = FALSE;
 static bool silc_log_no_init = FALSE;
 
-/* This is only needed during starting up -- don't lose any logging */
+/* This is only needed during starting up -- don't lose any logging message */
 static bool silc_log_starting = TRUE;
 
 /* The type wrapper utility. Translates a SilcLogType id to the corresponding
@@ -144,7 +145,7 @@ static bool silc_log_reset(SilcLog log)
   if (!log->filename) return FALSE;
   if (!(log->fp = fopen(log->filename, "a+"))) {
     SILC_LOG_WARNING(("Couldn't reset logfile %s for type \"%s\": %s",
-       log->filename, log->typename, strerror(errno)));
+                     log->filename, log->typename, strerror(errno)));
     return FALSE;
   }
   return TRUE;
@@ -170,28 +171,28 @@ SILC_TASK_CALLBACK(silc_log_fflush_callback)
 
 /* Outputs the log message to the first available channel. Channels are
  * ordered by importance (see SilcLogType documentation).
- * More importants channels can be printed on less important ones, but not
+ * More important channels can be printed on less important ones, but not
  * vice-versa. */
 
 void silc_log_output(SilcLogType type, char *string)
 {
-  char *typename;
+  char *typename = NULL;
   FILE *fp;
   SilcLog log;
 
   if ((type > SILC_LOG_MAX) || !(log = silc_log_find_by_type(type)))
     goto end;
 
+  /* Save the original typename, because even if we redirect the message
+   * to another channel we'll keep however the original channel name */
+  typename = log->typename;
+
   /* If there is a custom callback set, use it and return. */
   if (log->cb) {
     if ((*log->cb)(type, string, log->context))
       goto end;
   }
 
-  /* save the original typename, because if we redirect the channel we
-   * keep however the original destination channel name */
-  typename = log->typename;
-
   if (!silc_log_scheduled) {
     if (silc_log_no_init == FALSE) {
       fprintf(stderr,
@@ -225,6 +226,11 @@ void silc_log_output(SilcLogType type, char *string)
   }
 
  end:
+  /* If debugging, also output the logging message to the console */
+  if (typename && silc_debug) {
+    fprintf(stderr, "[Logging] [%s] %s\n", typename, string);
+    fflush(stderr);
+  }
   silc_free(string);
 }
 
@@ -335,6 +341,8 @@ void silc_log_reset_all() {
   SILC_LOG_DEBUG(("Resetting all logs"));
   SILC_FOREACH_LOG(u)
     silc_log_reset(&silclogs[u]);
+  /* Immediately flush any possible warning message */
+  silc_log_flush_all();
 }
 
 /* Outputs the debug message to stderr. */
index 30cfa07051811ae291fae38b81a0fd4cffbd55f0..30d64eba0e6b3ddf243782927a93324027e68c54 100644 (file)
@@ -53,7 +53,7 @@ typedef enum {
   /* This should be used for warnings and non critical failures */
   SILC_LOG_WARNING,
 
-  /* Generic error and critical failures messages */
+  /* Generic error and critical failure messages */
   SILC_LOG_ERROR,
 
   /* Fatal messages (usually situations that will lead to a program crash */
@@ -506,8 +506,8 @@ void silc_log_flush_all();
  *
  *    Forces all logging channels to close and reopen their streams.  Useful
  *    for example after a SIGHUP signal.
- *    Please note that this function could cause some warning messages if
- *    some logging channel points to an illegal filename.
+ *    Please note that this function could generate some warning messages if
+ *    one or more logging channels point to an illegal filename.
  *
  ***/
 void silc_log_reset_all();
index 3703c30e0073233bc0953a0136067cc46c23db95..662390546eec28e0b0d619f412c97d6fb9c6bfe7 100644 (file)
@@ -4,7 +4,7 @@
 
   Author: Pekka Riikonen <priikone@poseidon.pspt.fi>
 
-  Copyright (C) 1997 - 2000 Pekka Riikonen
+  Copyright (C) 1997 - 2002 Pekka Riikonen
 
   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
@@ -23,7 +23,6 @@
 /* $Id$ */
 
 #include "silcincludes.h"
-#include "silcprotocol.h"
 
 /* Dynamically registered protocols */
 SilcProtocolObject *silc_protocol_list = NULL;
@@ -34,17 +33,17 @@ SilcProtocolObject *silc_protocol_list = NULL;
 void silc_protocol_register(SilcProtocolType type,
                            SilcProtocolCallback callback)
 {
-  SilcProtocolObject *new;
+  SilcProtocolObject *proto_new;
 
-  new = silc_calloc(1, sizeof(*new));
-  new->type = type;
-  new->callback = callback;
+  proto_new = silc_calloc(1, sizeof(*proto_new));
+  proto_new->type = type;
+  proto_new->callback = callback;
 
   if (!silc_protocol_list)
-    silc_protocol_list = new;
+    silc_protocol_list = proto_new;
   else {
-    new->next = silc_protocol_list;
-    silc_protocol_list = new;
+    proto_new->next = silc_protocol_list;
+    silc_protocol_list = proto_new;
   }
 }