X-Git-Url: http://git.silcnet.org/gitweb/?a=blobdiff_plain;f=lib%2Fsilcutil%2Fsilclog.c;h=d0bec0c1c4320c5e45cc7cec183f5614b0f4c6c9;hb=e7b6c157b80152bf9fb9266e6bdd93f9fb0db776;hp=82eb52401b252905e9fe09add2c23c77eadc6ab9;hpb=2c21b860be4a8e5bb2868c14cd3932e51a3a9e2e;p=silc.git diff --git a/lib/silcutil/silclog.c b/lib/silcutil/silclog.c index 82eb5240..d0bec0c1 100644 --- a/lib/silcutil/silclog.c +++ b/lib/silcutil/silclog.c @@ -4,7 +4,7 @@ Author: Pekka Riikonen - Copyright (C) 1997 - 2006 Pekka Riikonen + Copyright (C) 1997 - 2007 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 @@ -183,7 +183,7 @@ void silc_log_output(SilcLogType type, char *string) if (!silclog.scheduled) { if (silclog.no_init == FALSE) { fprintf(stderr, - "Warning, trying to output without log files initialization, " + "Warning, log files not initialized, " "log output is going to stderr\n"); silclog.no_init = TRUE; } @@ -243,6 +243,9 @@ SilcBool silc_log_set_file(SilcLogType type, char *filename, FILE *fp = NULL; SilcLog log; + if (!scheduler) + scheduler = silc_schedule_get_global(); + log = silc_log_get_context(type); if (!log) return FALSE; @@ -424,7 +427,7 @@ void silc_log_set_debug_string(const char *debug_string) int len; if ((strchr(debug_string, '(') && strchr(debug_string, ')')) || strchr(debug_string, '$')) - string = strdup(debug_string); + string = silc_strdup(debug_string); else string = silc_string_regexify(debug_string); len = strlen(string); @@ -486,6 +489,8 @@ void silc_log_debug_hexdump(SilcBool enable) void silc_log_output_debug(char *file, const char *function, int line, char *string) { + SilcTimeStruct curtime; + #ifndef SILC_SYMBIAN if (!silclog.debug) goto end; @@ -501,6 +506,8 @@ void silc_log_output_debug(char *file, const char *function, } #endif /* !SILC_SYMBIAN */ + silc_time_value(0, &curtime); + #ifdef SILC_WIN32 if (strrchr(function, '\\')) fprintf(stderr, "%s:%d: %s\n", strrchr(function, '\\') + 1, line, string); @@ -509,10 +516,12 @@ void silc_log_output_debug(char *file, const char *function, #ifdef SILC_SYMBIAN silc_symbian_debug(function, line, string); #else - fprintf(stderr, "%s:%d: %s\n", function, line, string); + fprintf(stderr, "%02d:%02d:%02d %s:%d: %s\n", curtime.hour, + curtime.minute, curtime.second, function, line, + string); fflush(stderr); #endif /* SILC_SYMBIAN */ - + end: silc_free(string); } @@ -523,10 +532,6 @@ void silc_log_output_hexdump(char *file, const char *function, int line, void *data_in, SilcUInt32 len, char *string) { - int i, k; - int off, pos, count; - unsigned char *data = (unsigned char *)data_in; - #ifndef SILC_SYMBIAN if (!silclog.debug_hexdump) goto end; @@ -544,60 +549,7 @@ void silc_log_output_hexdump(char *file, const char *function, fprintf(stderr, "%s:%d: %s\n", function, line, string); - k = 0; - pos = 0; - count = 16; - off = len % 16; - while (1) { - if (off) { - if ((len - pos) < 16 && (len - pos <= len - off)) - count = off; - } else { - if (pos == len) - count = 0; - } - if (off == len) - count = len; - - if (count) - fprintf(stderr, "%08X ", k++ * 16); - - for (i = 0; i < count; i++) { - fprintf(stderr, "%02X ", data[pos + i]); - - if ((i + 1) % 4 == 0) - fprintf(stderr, " "); - } - - if (count && count < 16) { - int j; - - for (j = 0; j < 16 - count; j++) { - fprintf(stderr, " "); - - if ((j + count + 1) % 4 == 0) - fprintf(stderr, " "); - } - } - - for (i = 0; i < count; i++) { - char ch; - - if (data[pos] < 32 || data[pos] >= 127) - ch = '.'; - else - ch = data[pos]; - - fprintf(stderr, "%c", ch); - pos++; - } - - if (count) - fprintf(stderr, "\n"); - - if (count < 16) - break; - } + silc_hexdump(data_in, len, stderr); end: silc_free(string);