MACSio  0.9
Multi-purpose, Application-Centric, Scalable I/O Proxy App
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
debug.c
Go to the documentation of this file.
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 <stdio.h>
15 #include <stdlib.h>
16 #include <string.h>
17 #include <stdarg.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) { _debug = debug; }
37 int mc_get_debug(void) { return _debug; }
38 
39 extern void mc_set_syslog(int syslog)
40 {
41  _syslog = syslog;
42 }
43 
44 void mc_debug(const char *msg, ...)
45 {
46  va_list ap;
47  if(_debug) {
48  va_start(ap, msg);
49 #if HAVE_VSYSLOG
50  if(_syslog) {
51  vsyslog(LOG_DEBUG, msg, ap);
52  } else
53 #endif
54  vprintf(msg, ap);
55  va_end(ap);
56  }
57 }
58 
59 void mc_error(const char *msg, ...)
60 {
61  va_list ap;
62  va_start(ap, msg);
63 #if HAVE_VSYSLOG
64  if(_syslog) {
65  vsyslog(LOG_ERR, msg, ap);
66  } else
67 #endif
68  vfprintf(stderr, msg, ap);
69  va_end(ap);
70 }
71 
72 void mc_info(const char *msg, ...)
73 {
74  va_list ap;
75  va_start(ap, msg);
76 #if HAVE_VSYSLOG
77  if(_syslog) {
78  vsyslog(LOG_INFO, msg, ap);
79  } else
80 #endif
81  vfprintf(stderr, msg, ap);
82  va_end(ap);
83 }
void mc_debug(const char *msg,...)
Definition: debug.c:44
void mc_error(const char *msg,...)
Definition: debug.c:59
static int _syslog
Definition: debug.c:33
static int _debug
Definition: debug.c:34
void mc_set_debug(int debug)
Definition: debug.c:36
int mc_get_debug(void)
Definition: debug.c:37
void mc_info(const char *msg,...)
Definition: debug.c:72
void mc_set_syslog(int syslog)
Definition: debug.c:39