blob: 6ae1ca3c4f5048d9dbd350097a7bc53db8a050b3 [file] [log] [blame]
Michael Clarkf0d08882007-03-13 08:26:18 +00001/*
2 * $Id: debug.c,v 1.3 2004/08/07 03:11:38 mclark Exp $
3 *
4 * Copyright Metaparadigm Pte. Ltd. 2004.
5 * Michael Clark <michael@metaparadigm.com>
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public (LGPL)
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details: http://www.gnu.org/
16 *
17 */
18
19#include <stdio.h>
20#include <stdlib.h>
21#include <string.h>
22#include <stdarg.h>
23#include <syslog.h>
24#include <unistd.h>
25#include <sys/param.h>
26
27#include "debug.h"
28
29
30static int _syslog = 0;
31static int _debug = 0;
32
33void mc_set_debug(int debug) { _debug = debug; }
34int mc_get_debug() { return _debug; }
35
36extern void mc_set_syslog(int syslog)
37{
38 _syslog = syslog;
39}
40
41void mc_abort(const char *msg, ...)
42{
43 va_list ap;
44 va_start(ap, msg);
45 if(_syslog) vsyslog(LOG_ERR, msg, ap);
46 else vprintf(msg, ap);
47 exit(1);
48}
49
50
51void mc_debug(const char *msg, ...)
52{
53 va_list ap;
54 if(_debug) {
55 va_start(ap, msg);
56 if(_syslog) vsyslog(LOG_DEBUG, msg, ap);
57 else vprintf(msg, ap);
58 }
59}
60
61void mc_error(const char *msg, ...)
62{
63 va_list ap;
64 va_start(ap, msg);
65 if(_syslog) vsyslog(LOG_ERR, msg, ap);
66 else vfprintf(stderr, msg, ap);
67}
68
69void mc_info(const char *msg, ...)
70{
71 va_list ap;
72 va_start(ap, msg);
73 if(_syslog) vsyslog(LOG_INFO, msg, ap);
74 else vfprintf(stderr, msg, ap);
75}