Main Page | Data Structures | Directories | File List | Data Fields

src/debug.c

00001 /********************************************************************\
00002  * This program is free software; you can redistribute it and/or    *
00003  * modify it under the terms of the GNU General Public License as   *
00004  * published by the Free Software Foundation; either version 2 of   *
00005  * the License, or (at your option) any later version.              *
00006  *                                                                  *
00007  * This program is distributed in the hope that it will be useful,  *
00008  * but WITHOUT ANY WARRANTY; without even the implied warranty of   *
00009  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    *
00010  * GNU General Public License for more details.                     *
00011  *                                                                  *
00012  * You should have received a copy of the GNU General Public License*
00013  * along with this program; if not, contact:                        *
00014  *                                                                  *
00015  * Free Software Foundation           Voice:  +1-617-542-5942       *
00016  * 59 Temple Place - Suite 330        Fax:    +1-617-542-2652       *
00017  * Boston, MA  02111-1307,  USA       gnu@gnu.org                   *
00018  *                                                                  *
00019 \********************************************************************/
00020 
00021 /* $Header: /cvsroot/wifidog/wifidog/src/debug.c,v 1.8 2004/10/08 02:59:16 alexcv Exp $ */
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 

Generated on Sun Apr 3 20:04:45 2005 for WifiDog by  doxygen 1.4.1