X-Git-Url: http://www.privoxy.org/gitweb/?p=privoxy.git;a=blobdiff_plain;f=errlog.c;h=dc1584503ea737eb1bdd83f0026baf0789dfb25f;hp=05ed02eb824bc3b784ff2304f67ca059014fde81;hb=8a5751cc96dd085fcbcc34bef77499306bddc0c0;hpb=9cd09db299cbd76b7fc3680cfbe3f3ea77c9f732 diff --git a/errlog.c b/errlog.c index 05ed02eb..dc158450 100644 --- a/errlog.c +++ b/errlog.c @@ -1,4 +1,4 @@ -const char errlog_rcs[] = "$Id: errlog.c,v 1.79 2008/10/20 17:09:25 fabiankeil Exp $"; +const char errlog_rcs[] = "$Id: errlog.c,v 1.91 2009/03/18 21:56:30 fabiankeil Exp $"; /********************************************************************* * * File : $Source: /cvsroot/ijbswa/current/errlog.c,v $ @@ -6,7 +6,7 @@ const char errlog_rcs[] = "$Id: errlog.c,v 1.79 2008/10/20 17:09:25 fabiankeil E * Purpose : Log errors to a designated destination in an elegant, * printf-like fashion. * - * Copyright : Written by and Copyright (C) 2001-2007 the SourceForge + * Copyright : Written by and Copyright (C) 2001-2009 the SourceForge * Privoxy team. http://www.privoxy.org/ * * Based on the Internet Junkbuster originally written @@ -33,6 +33,52 @@ const char errlog_rcs[] = "$Id: errlog.c,v 1.79 2008/10/20 17:09:25 fabiankeil E * * Revisions : * $Log: errlog.c,v $ + * Revision 1.91 2009/03/18 21:56:30 fabiankeil + * In init_error_log(), suppress the "(Re-)Opening logfile" message if + * we're still logging to stderr. This restores the "silent mode", but + * with LOG_LEVEL_INFO enabled, the show_version() info is written to + * the logfile as intended. + * + * Revision 1.90 2009/03/18 20:43:19 fabiankeil + * Don't enable LOG_LEVEL_INFO by default and don't apply the user's + * debug settings until the logfile has been opened (if there is one). + * Patch submitted by Roland in #2624120. + * + * Revision 1.89 2009/03/07 12:56:12 fabiankeil + * Add log_error() support for unsigned long long (%lld). + * + * Revision 1.88 2009/03/07 11:34:36 fabiankeil + * Omit timestamp and thread id in the mingw32 message box. + * + * Revision 1.87 2009/03/01 18:28:24 fabiankeil + * Help clang understand that we aren't dereferencing + * NULL pointers here. + * + * Revision 1.86 2009/02/09 21:21:15 fabiankeil + * Now that init_log_module() is called earlier, call show_version() + * later on from main() directly so it doesn't get called for --help + * or --version. + * + * Revision 1.85 2009/02/06 17:51:38 fabiankeil + * Be prepared if I break the log module initialization again. + * + * Revision 1.84 2008/12/14 15:46:22 fabiankeil + * Give crunched requests their own log level. + * + * Revision 1.83 2008/12/04 18:14:32 fabiankeil + * Fix some cparser warnings. + * + * Revision 1.82 2008/11/23 16:06:58 fabiankeil + * Update a log message I missed in 1.80. + * + * Revision 1.81 2008/11/23 15:59:27 fabiankeil + * - Update copyright range. + * - Remove stray line breaks in a log message + * nobody is supposed to see anyway. + * + * Revision 1.80 2008/11/23 15:49:49 fabiankeil + * In log_error(), don't surround the thread id with "Privoxy(" and ")". + * * Revision 1.79 2008/10/20 17:09:25 fabiankeil * Update init_error_log() description to match reality. * @@ -443,7 +489,7 @@ const char errlog_h_rcs[] = ERRLOG_H_VERSION; static FILE *logfp = NULL; /* logging detail level. XXX: stupid name. */ -static int debug = (LOG_LEVEL_FATAL | LOG_LEVEL_ERROR | LOG_LEVEL_INFO); +static int debug = (LOG_LEVEL_FATAL | LOG_LEVEL_ERROR); /* static functions */ static void fatal_error(const char * error_message); @@ -488,8 +534,8 @@ static inline void unlock_loginit() {} * Function : fatal_error * * Description : Displays a fatal error to standard error (or, on - * a WIN32 GUI, to a dialog box), and exits - * JunkBuster with status code 1. + * a WIN32 GUI, to a dialog box), and exits Privoxy + * with status code 1. * * Parameters : * 1 : error_message = The error message to display. @@ -497,10 +543,17 @@ static inline void unlock_loginit() {} * Returns : Does not return. * *********************************************************************/ -static void fatal_error(const char * error_message) +static void fatal_error(const char *error_message) { #if defined(_WIN32) && !defined(_WIN_CONSOLE) - MessageBox(g_hwndLogFrame, error_message, "Privoxy Error", + /* Skip timestamp and thread id for the message box. */ + const char *box_message = strstr(error_message, "Fatal error"); + if (NULL == box_message) + { + /* Shouldn't happen but ... */ + box_message = error_message; + } + MessageBox(g_hwndLogFrame, box_message, "Privoxy Error", MB_OK | MB_ICONERROR | MB_TASKMODAL | MB_SETFOREGROUND | MB_TOPMOST); /* Cleanup - remove taskbar icon etc. */ @@ -535,7 +588,7 @@ static void fatal_error(const char * error_message) * Returns : Nothing. * *********************************************************************/ -static void show_version(const char *prog_name) +void show_version(const char *prog_name) { log_error(LOG_LEVEL_INFO, "Privoxy version " VERSION); if (prog_name != NULL) @@ -559,13 +612,12 @@ static void show_version(const char *prog_name) * Returns : Nothing. * *********************************************************************/ -void init_log_module(const char *prog_name) +void init_log_module(void) { lock_logfile(); logfp = stderr; unlock_logfile(); set_debug_level(debug); - show_version(prog_name); } @@ -639,7 +691,7 @@ void init_error_log(const char *prog_name, const char *logfname) lock_loginit(); - if (logfp != NULL) + if ((logfp != NULL) && (logfp != stderr)) { log_error(LOG_LEVEL_INFO, "(Re-)Opening logfile \'%s\'", logfname); } @@ -693,18 +745,7 @@ void init_error_log(const char *prog_name, const char *logfname) logfp = fp; unlock_logfile(); -#if !defined(_WIN32) - /* - * Prevent the Windows GUI from showing the version two - * times in a row on startup. It already displayed the show_version() - * call from init_log_module() that other systems write to stderr. - * - * This means mingw32 users will never see the version in their - * log file, but I assume they wouldn't look for it there anyway - * and simply use the "Help/About Privoxy" menu. - */ show_version(prog_name); -#endif /* def unix */ unlock_loginit(); @@ -795,7 +836,7 @@ static inline size_t get_log_timestamp(char *buffer, size_t buffer_size) #endif length = strftime(buffer, buffer_size, "%b %d %H:%M:%S", &tm_now); - if (length > 0) + if (length > (size_t)0) { msecs_length = snprintf(buffer+length, buffer_size - length, ".%.3ld", msecs); } @@ -866,7 +907,7 @@ static inline size_t get_clf_timestamp(char *buffer, size_t buffer_size) length = strftime(buffer, buffer_size, "%d/%b/%Y:%H:%M:%S ", tm_now); - if (length > 0) + if (length > (size_t)0) { tz_length = snprintf(buffer+length, buffer_size-length, "%+03d%02d", mins / 60, abs(mins) % 60); @@ -941,6 +982,9 @@ static inline const char *get_log_level_string(int loglevel) case LOG_LEVEL_DEANIMATE: log_level_string = "Gif-Deanimate"; break; + case LOG_LEVEL_CRUNCH: + log_level_string = "Crunch"; + break; case LOG_LEVEL_CGI: log_level_string = "CGI"; break; @@ -991,7 +1035,7 @@ void log_error(int loglevel, const char *fmt, ...) * the taskbar icon animate. (There is an option to disable * this but checking that is handled inside LogShowActivity()). */ - if (loglevel == LOG_LEVEL_GPC) + if ((loglevel == LOG_LEVEL_GPC) || (loglevel == LOG_LEVEL_CRUNCH)) { LogShowActivity(); } @@ -1008,6 +1052,11 @@ void log_error(int loglevel, const char *fmt, ...) #endif ) { + if (loglevel == LOG_LEVEL_FATAL) + { + fatal_error("Fatal error. You're not supposed to" + "see this message. Please file a bug report."); + } return; } @@ -1023,9 +1072,10 @@ void log_error(int loglevel, const char *fmt, ...) if (NULL == outbuf_save) { snprintf(tempbuf, sizeof(tempbuf), - "%s %08lx Fatal error: log_error() failed to allocate buffer memory.\n" - "\nExiting.", timestamp, thread_id); + "%s %08lx Fatal error: Out of memory in log_error().", + timestamp, thread_id); fatal_error(tempbuf); /* Exit */ + return; } } outbuf = outbuf_save; @@ -1085,7 +1135,7 @@ void log_error(int loglevel, const char *fmt, ...) snprintf(tempbuf, sizeof(tempbuf), "%u", uval); break; case 'l': - /* this is a modifier that must be followed by u or d */ + /* this is a modifier that must be followed by u, lu, or d */ ch = *src++; if (ch == 'd') { @@ -1097,6 +1147,12 @@ void log_error(int loglevel, const char *fmt, ...) ulval = va_arg( ap, unsigned long ); snprintf(tempbuf, sizeof(tempbuf), "%lu", ulval); } + else if ((ch == 'l') && (*src == 'u')) + { + unsigned long long lluval = va_arg(ap, unsigned long long); + snprintf(tempbuf, sizeof(tempbuf), "%llu", lluval); + ch = *src++; + } else { snprintf(tempbuf, sizeof(tempbuf), "Bad format string: \"%s\"", fmt); @@ -1145,7 +1201,7 @@ void log_error(int loglevel, const char *fmt, ...) format_string = "[counted string lenght < 0]"; } } - else if (ival >= sizeof(tempbuf)) + else if ((size_t)ival >= sizeof(tempbuf)) { /* * String is too long, copy as much as possible. @@ -1237,8 +1293,9 @@ void log_error(int loglevel, const char *fmt, ...) assert(outbuf[log_buffer_size] == '\0'); snprintf(outbuf, log_buffer_size, - "%s Privoxy(%08lx) Fatal error: log_error()'s sanity checks failed. length: %d\n" - "Exiting.", timestamp, thread_id, (int)length); + "%s %08lx Fatal error: log_error()'s sanity checks failed." + "length: %d. Exiting.", + timestamp, thread_id, (int)length); loglevel = LOG_LEVEL_FATAL; }