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
00033 #include "conf.h"
00034
00037 void
00038 _debug(char *filename, int line, int level, char *format, ...)
00039 {
00040 char buf[28];
00041 va_list vlist;
00042 s_config *config = config_get_config();
00043 time_t ts;
00044
00045 time(&ts);
00046
00047 if (config->debuglevel >= level) {
00048 va_start(vlist, format);
00049
00050 if (level <= LOG_WARNING) {
00051 fprintf(stderr, "[%d][%.24s](%s:%d) ", level, ctime_r(&ts, buf),
00052 filename, line);
00053 vfprintf(stderr, format, vlist);
00054 fputc('\n', stderr);
00055 } else if (!config->daemon) {
00056 fprintf(stdout, "[%d][%.24s](%s:%d) ", level, ctime_r(&ts, buf),
00057 filename, line);
00058 vfprintf(stdout, format, vlist);
00059 fputc('\n', stdout);
00060 fflush(stdout);
00061 }
00062
00063 if (config->log_syslog) {
00064 openlog("wifidog", LOG_PID, config->syslog_facility);
00065 vsyslog(level, format, vlist);
00066 closelog();
00067 }
00068 }
00069 }
00070