blob: 7971744ccffac45e98e712e34b640a022a3996f6 [file] [log] [blame]
w.dengc6bcc0a2025-08-13 17:39:36 +08001/*
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
33static int _syslog = 0;
34static int _debug = 0;
35
36void mc_set_debug(int debug)
37{
38 _debug = debug;
39}
40int mc_get_debug(void)
41{
42 return _debug;
43}
44
45extern void mc_set_syslog(int syslog)
46{
47 _syslog = syslog;
48}
49
50void 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
68void 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
83void 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}