diff options
Diffstat (limited to 'debug.c')
-rw-r--r-- | debug.c | 46 |
1 files changed, 38 insertions, 8 deletions
@@ -4,22 +4,32 @@ #include <stdio.h> #include "antispam-plugin.h" +enum antispam_debug_target debug_target; +int verbose_debug; + static void _debug(const char *format, va_list ap) { const char *fmt; + if (debug_target == ADT_NONE) + return; + t_push(); fmt = t_strconcat(stringify(PLUGINNAME), ": ", format, NULL); -#if defined(DEBUG_SYSLOG) - vsyslog(LOG_DEBUG, fmt, ap); -#elif defined(DEBUG_STDERR) - vfprintf(stderr, fmt, ap); - fflush(stderr); -#else -#error no logging method -#endif + switch (debug_target) { + case ADT_NONE: + break; + case ADT_SYSLOG: + vsyslog(LOG_DEBUG, fmt, ap); + break; + case ADT_STDERR: + vfprintf(stderr, fmt, ap); + fflush(stderr); + break; + } + t_pop(); } @@ -64,3 +74,23 @@ void debugv(char **args) debug("%s", buf); t_pop(); } + +void debugv_not_stderr(char **args) +{ + if (debug_target == ADT_STDERR) + return; + + debugv(args); +} + +void debug_verbose(const char *fmt, ...) +{ + va_list args; + + if (!verbose_debug) + return; + + va_start(args, fmt); + _debug(fmt, args); + va_end(args); +} |