00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00027 #include <stdio.h>
00028 #include <errno.h>
00029 #include <syslog.h>
00030 #include <stdarg.h>
00031 #include <time.h>
00032 #include <unistd.h>
00033
00034 #include "conf.h"
00035
00038 void
00039 _debug(char *filename, int line, int level, char *format, ...)
00040 {
00041 char buf[28];
00042 va_list vlist;
00043 s_config *config = config_get_config();
00044 time_t ts;
00045
00046 time(&ts);
00047
00048 if (config->debuglevel >= level) {
00049 va_start(vlist, format);
00050
00051 if (level <= LOG_WARNING) {
00052 fprintf(stderr, "[%d][%.24s][%u](%s:%d) ", level, ctime_r(&ts, buf), getpid(),
00053 filename, line);
00054 vfprintf(stderr, format, vlist);
00055 fputc('\n', stderr);
00056 } else if (!config->daemon) {
00057 fprintf(stdout, "[%d][%.24s][%u](%s:%d) ", level, ctime_r(&ts, buf), getpid(),
00058 filename, line);
00059 vfprintf(stdout, format, vlist);
00060 fputc('\n', stdout);
00061 fflush(stdout);
00062 }
00063
00064 if (config->log_syslog) {
00065 openlog("wifidog", LOG_PID, config->syslog_facility);
00066 vsyslog(level, format, vlist);
00067 closelog();
00068 }
00069 }
00070 }
00071