Merged from silc_1_0_branch (second merge).
[silc.git] / lib / silcutil / silclog.c
index 4a70cbc5a7d47d0ba6a665f5dafd104d7efb3b5f..736edb03f4daa8b671ef8a6183797dfec908b93d 100644 (file)
@@ -2,7 +2,7 @@
 
   silclog.c
 
-  Author: Johnny Mnemonic <johnny@themnemonic.org>
+  Author: Giovanni Giacobbi <giovanni@giacobbi.net>
 
   Copyright (C) 1997 - 2002 Pekka Riikonen
 
@@ -49,6 +49,9 @@ static struct SilcLogStruct silclogs[SILC_LOG_MAX] = {
   {"", NULL, 0, "Fatal", SILC_LOG_FATAL, NULL, NULL},
 };
 
+/* Causes logging output to contain timestamps */
+bool silc_log_timestamp = TRUE;
+
 /* If TRUE, log files will be flushed for each log input */
 bool silc_log_quick = FALSE;
 
@@ -114,15 +117,17 @@ static void silc_log_checksize(SilcLog log)
                    log->filename, oldfp));
     return;
   }
-  if (size < log->maxsize) return;
+  if (size < log->maxsize)
+    return;
 
   /* It's too big */
   fprintf(log->fp, "[%s] [%s] Cycling log file, over max "
          "logsize (%lu kilobytes)\n",
-         silc_get_time(), log->typename, log->maxsize / 1024);
+         silc_get_time(0), log->typename, log->maxsize / 1024);
   fflush(log->fp);
   fclose(log->fp);
-  snprintf(newname, sizeof(newname), "%s.old", log->filename);
+  memset(newname, 0, sizeof(newname));
+  snprintf(newname, sizeof(newname) - 1, "%s.old", log->filename);
   unlink(newname);
 
   /* I heard the following syscall may cause portability issues, but I don't
@@ -220,7 +225,12 @@ void silc_log_output(SilcLogType type, char *string)
   goto end;
 
  found:
-  fprintf(fp, "[%s] [%s] %s\n", silc_get_time(), typename, string);
+  /* writes the logging string to the selected channel */
+  if (silc_log_timestamp)
+    fprintf(fp, "[%s] [%s] %s\n", silc_get_time(0), typename, string);
+  else
+    fprintf(fp, "[%s] %s\n", typename, string);
+
   if (silc_log_quick || silc_log_starting) {
     fflush(fp);
     if (log) /* we may have been redirected to stderr */