silclog.c
- Author: Johnny Mnemonic <johnny@themnemonic.org>
+ Author: Giovanni Giacobbi <giovanni@giacobbi.net>
- Copyright (C) 1997 - 2002 Pekka Riikonen
+ Copyright (C) 1997 - 2005 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
{"", 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;
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, (unsigned long)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
if (!(log->fp = fopen(log->filename, "w")))
SILC_LOG_WARNING(("Couldn't reopen logfile %s for type \"%s\": %s",
log->filename, log->typename, strerror(errno)));
+#ifdef HAVE_CHMOD
+ chmod(log->filename, 0600);
+#endif /* HAVE_CHMOD */
}
/* Reset a logging channel (close and reopen) */
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 */
filename, strerror(errno));
return FALSE;
}
+#ifdef HAVE_CHMOD
+ chmod(filename, 0600);
+#endif /* HAVE_CHMOD */
}
/* clean the logging channel */
if (silc_log_scheduled)
return TRUE;
- /* Add schedule hook with a short delay to make sure we'll use
+ /* Add schedule hook with a short delay to make sure we'll use
right delay */
silc_schedule_task_add(scheduler, 0, silc_log_fflush_callback,
(void *) scheduler, 10, 0,
/* Outputs the debug message to stderr. */
-void silc_log_output_debug(char *file, char *function,
+void silc_log_output_debug(char *file, const char *function,
int line, char *string)
{
if (!silc_debug)
goto end;
if (silc_log_debug_cb) {
- if ((*silc_log_debug_cb)(file, function, line, string,
+ if ((*silc_log_debug_cb)(file, (char *)function, line, string,
silc_log_debug_context))
goto end;
}
/* Hexdumps a message */
-void silc_log_output_hexdump(char *file, char *function,
+void silc_log_output_hexdump(char *file, const char *function,
int line, void *data_in,
SilcUInt32 len, char *string)
{
goto end;
if (silc_log_hexdump_cb) {
- if ((*silc_log_hexdump_cb)(file, function, line, data_in, len, string,
+ if ((*silc_log_hexdump_cb)(file, (char *)function, line,
+ data_in, len, string,
silc_log_hexdump_context))
goto end;
}
len = strlen(string);
if (len >= sizeof(silc_log_debug_string))
len = sizeof(silc_log_debug_string) - 1;
+ memset(silc_log_debug_string, 0, sizeof(silc_log_debug_string));
strncpy(silc_log_debug_string, string, len);
silc_free(string);
}