1 /* 2 * $Id: debug.c,v 1.5 2006/01/26 02:16:28 mclark Exp $ 3 * 4 * Copyright (c) 2004, 2005 Metaparadigm Pte. Ltd. 5 * Michael Clark <michael@metaparadigm.com> 6 * 7 * This library is free software; you can redistribute it and/or modify 8 * it under the terms of the MIT license. See COPYING for details. 9 * 10 */ 11 12 #include "config.h" 13 14 #include <stdarg.h> 15 #include <stdio.h> 16 #include <stdlib.h> 17 #include <string.h> 18 19 #if HAVE_SYSLOG_H 20 #include <syslog.h> 21 #endif /* HAVE_SYSLOG_H */ 22 23 #if HAVE_UNISTD_H 24 #include <unistd.h> 25 #endif /* HAVE_UNISTD_H */ 26 27 #if HAVE_SYS_PARAM_H 28 #include <sys/param.h> 29 #endif /* HAVE_SYS_PARAM_H */ 30 31 #include "debug.h" 32 33 static int _syslog = 0; 34 static int _debug = 0; 35 36 void mc_set_debug(int debug) 37 { 38 _debug = debug; 39 } 40 int mc_get_debug(void) 41 { 42 return _debug; 43 } 44 45 extern void mc_set_syslog(int syslog) 46 { 47 _syslog = syslog; 48 } 49 50 void mc_debug(const char *msg, ...) 51 { 52 va_list ap; 53 if (_debug) 54 { 55 va_start(ap, msg); 56 #if HAVE_VSYSLOG 57 if (_syslog) 58 { 59 vsyslog(LOG_DEBUG, msg, ap); 60 } 61 else 62 #endif 63 vprintf(msg, ap); 64 va_end(ap); 65 } 66 } 67 68 void mc_error(const char *msg, ...) 69 { 70 va_list ap; 71 va_start(ap, msg); 72 #if HAVE_VSYSLOG 73 if (_syslog) 74 { 75 vsyslog(LOG_ERR, msg, ap); 76 } 77 else 78 #endif 79 vfprintf(stderr, msg, ap); 80 va_end(ap); 81 } 82 83 void mc_info(const char *msg, ...) 84 { 85 va_list ap; 86 va_start(ap, msg); 87 #if HAVE_VSYSLOG 88 if (_syslog) 89 { 90 vsyslog(LOG_INFO, msg, ap); 91 } 92 else 93 #endif 94 vfprintf(stderr, msg, ap); 95 va_end(ap); 96 } 97
This page was automatically generated by LXR 0.3.1. • OpenWrt