/*
- * $Id: debug.cc,v 1.81 2001/02/07 18:56:52 hno Exp $
+ * $Id: debug.cc,v 1.82 2001/06/26 21:07:09 wessels Exp $
*
* DEBUG: section 0 Debug Routines
* AUTHOR: Harvest Derived
static int Ctx_Lock = 0;
static const char *debugLogTime(time_t);
static void ctx_print(void);
+#if HAVE_SYSLOG
+static void _db_print_syslog(const char *format, va_list args);
+#endif
+static void _db_print_stderr(const char *format, va_list args);
+static void _db_print_file(const char *format, va_list args);
-#if STDC_HEADERS
void
+#if STDC_HEADERS
_db_print(const char *format,...)
{
-#if defined(__QNX__)
- va_list eargs;
-#endif
va_list args;
#else
-void
_db_print(va_alist)
va_dcl
{
const char *format = NULL;
#endif
LOCAL_ARRAY(char, f, BUFSIZ);
-#if HAVE_SYSLOG
- LOCAL_ARRAY(char, tmpbuf, BUFSIZ);
-#endif
-
#if STDC_HEADERS
va_start(args, format);
-#if defined(__QNX__)
- va_start(eargs, format);
-#endif
#else
- va_start(args);
format = va_arg(args, const char *);
#endif
+ snprintf(f, BUFSIZ, "%s| %s",
+ debugLogTime(squid_curtime),
+ format);
+ _db_print_file(f, args);
+ _db_print_stderr(f, args);
+#if HAVE_SYSLOG
+ _db_print_syslog(format, args);
+#endif
+ va_end(args);
+}
+static void
+_db_print_file(const char *format, va_list args)
+{
if (debug_log == NULL)
return;
/* give a chance to context-based debugging to print current context */
if (!Ctx_Lock)
ctx_print();
- snprintf(f, BUFSIZ, "%s| %s",
- debugLogTime(squid_curtime),
- format);
-#if HAVE_SYSLOG
- /* level 0,1 go to syslog */
- if (_db_level <= 1 && opt_syslog_enable) {
- tmpbuf[0] = '\0';
- vsnprintf(tmpbuf, BUFSIZ, format, args);
- tmpbuf[BUFSIZ - 1] = '\0';
- syslog(_db_level == 0 ? LOG_WARNING : LOG_NOTICE, "%s", tmpbuf);
- }
-#endif /* HAVE_SYSLOG */
- /* write to log file */
-#if defined(__QNX__)
- vfprintf(debug_log, f, eargs);
-#else
- vfprintf(debug_log, f, args);
-#endif
+ vfprintf(debug_log, format, args);
if (!Config.onoff.buffered_logs)
fflush(debug_log);
- if (opt_debug_stderr >= _db_level && debug_log != stderr) {
-#if defined(__QNX__)
- vfprintf(stderr, f, eargs);
-#else
- vfprintf(stderr, f, args);
-#endif
- }
-#if defined(__QNX__)
- va_end(eargs);
-#endif
- va_end(args);
}
+static void
+_db_print_stderr(const char *format, va_list args)
+{
+ if (opt_debug_stderr < _db_level)
+ return;
+ if (debug_log == stderr)
+ return;
+ vfprintf(stderr, format, args);
+}
+
+#if HAVE_SYSLOG
+static void
+_db_print_syslog(const char *format, va_list args)
+{
+ LOCAL_ARRAY(char, tmpbuf, BUFSIZ);
+ /* level 0,1 go to syslog */
+ if (_db_level > 1)
+ return;
+ if (0 == opt_syslog_enable)
+ return;
+ tmpbuf[0] = '\0';
+ vsnprintf(tmpbuf, BUFSIZ, format, args);
+ tmpbuf[BUFSIZ - 1] = '\0';
+ syslog(_db_level == 0 ? LOG_WARNING : LOG_NOTICE, "%s", tmpbuf);
+}
+#endif /* HAVE_SYSLOG */
+
static void
debugArg(const char *arg)
{