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 0 : void mc_set_debug(int debug) { _debug = debug; }
37 0 : int mc_get_debug() { return _debug; }
38 :
39 0 : extern void mc_set_syslog(int syslog)
40 : {
41 0 : _syslog = syslog;
42 0 : }
43 :
44 0 : void mc_abort(const char *msg, ...)
45 : {
46 : va_list ap;
47 0 : va_start(ap, msg);
48 : #if HAVE_VSYSLOG
49 : if(_syslog) {
50 : vsyslog(LOG_ERR, msg, ap);
51 : } else
52 : #endif
53 0 : vprintf(msg, ap);
54 0 : exit(1);
55 : }
56 :
57 :
58 0 : void mc_debug(const char *msg, ...)
59 : {
60 : va_list ap;
61 0 : if(_debug) {
62 0 : va_start(ap, msg);
63 : #if HAVE_VSYSLOG
64 : if(_syslog) {
65 : vsyslog(LOG_DEBUG, msg, ap);
66 : } else
67 : #endif
68 0 : vprintf(msg, ap);
69 : }
70 0 : }
71 :
72 0 : void mc_error(const char *msg, ...)
73 : {
74 : va_list ap;
75 0 : va_start(ap, msg);
76 : #if HAVE_VSYSLOG
77 : if(_syslog) {
78 : vsyslog(LOG_ERR, msg, ap);
79 : } else
80 : #endif
81 0 : vfprintf(stderr, msg, ap);
82 0 : }
83 :
84 0 : void mc_info(const char *msg, ...)
85 : {
86 : va_list ap;
87 0 : va_start(ap, msg);
88 : #if HAVE_VSYSLOG
89 : if(_syslog) {
90 : vsyslog(LOG_INFO, msg, ap);
91 : } else
92 : #endif
93 0 : vfprintf(stderr, msg, ap);
94 0 : }
|