+ assert(NULL != log_level_string);
+
+ return log_level_string;
+}
+
+
+/*********************************************************************
+ *
+ * Function : log_error
+ *
+ * Description : This is the error-reporting and logging function.
+ *
+ * Parameters :
+ * 1 : loglevel = the type of message to be logged
+ * 2 : fmt = the main string we want logged, printf-like
+ * 3 : ... = arguments to be inserted in fmt (printf-like).
+ *
+ * Returns : N/A
+ *
+ *********************************************************************/
+void log_error(int loglevel, const char *fmt, ...)
+{
+ va_list ap;
+ char *outbuf = NULL;
+ static char *outbuf_save = NULL;
+ char tempbuf[BUFFER_SIZE];
+ size_t length = 0;
+ const char * src = fmt;
+ long thread_id;
+ char timestamp[30];
+ /*
+ * XXX: Make this a config option,
+ * why else do we allocate instead of using
+ * an array?
+ */
+ size_t log_buffer_size = BUFFER_SIZE;
+
+#if defined(_WIN32) && !defined(_WIN_CONSOLE)
+ /*
+ * Irrespective of debug setting, a GET/POST/CONNECT makes
+ * the taskbar icon animate. (There is an option to disable
+ * this but checking that is handled inside LogShowActivity()).
+ */
+ if (loglevel == LOG_LEVEL_GPC)
+ {
+ LogShowActivity();
+ }
+#endif /* defined(_WIN32) && !defined(_WIN_CONSOLE) */
+
+ /*
+ * verify that the loglevel applies to current
+ * settings and that logging is enabled.
+ * Bail out otherwise.
+ */
+ if ((0 == (loglevel & debug)) || (logfp == NULL))
+ {
+ return;
+ }
+
+ thread_id = get_thread_id();
+ get_log_timestamp(timestamp, sizeof(timestamp));
+
+ /* protect the whole function because of the static buffer (outbuf) */
+ lock_logfile();
+
+ if (NULL == outbuf_save)
+ {
+ outbuf_save = (char*)zalloc(log_buffer_size + 1); /* +1 for paranoia */
+ if (NULL == outbuf_save)
+ {
+ snprintf(tempbuf, sizeof(tempbuf),
+ "%s Privoxy(%08lx) Fatal error: log_error() failed to allocate buffer memory.\n"
+ "\nExiting.", timestamp, thread_id);
+ assert(NULL != logfp);
+ fputs(tempbuf, logfp);
+ unlock_logfile();
+ fatal_error(tempbuf); /* Exit */
+ }
+ }
+ outbuf = outbuf_save;
+
+ /*
+ * Memsetting the whole buffer to zero (in theory)
+ * makes things easier later on.
+ */
+ memset(outbuf, 0, log_buffer_size);
+
+ /* Add prefix for everything but Common Log Format messages */
+ if (loglevel != LOG_LEVEL_CLF)
+ {
+ length = (size_t)snprintf(outbuf, log_buffer_size, "%s Privoxy(%08lx) %s: ",
+ timestamp, thread_id, get_log_level_string(loglevel));
+ }
+