~ubuntu-branches/ubuntu/wily/bluez/wily

« back to all changes in this revision

Viewing changes to common/logging.c

ImportĀ upstreamĀ versionĀ 4.81

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 *
3
 
 *  BlueZ - Bluetooth protocol stack for Linux
4
 
 *
5
 
 *  Copyright (C) 2004-2009  Marcel Holtmann <marcel@holtmann.org>
6
 
 *
7
 
 *
8
 
 *  This program is free software; you can redistribute it and/or modify
9
 
 *  it under the terms of the GNU General Public License as published by
10
 
 *  the Free Software Foundation; either version 2 of the License, or
11
 
 *  (at your option) any later version.
12
 
 *
13
 
 *  This program is distributed in the hope that it will be useful,
14
 
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 
 *  GNU General Public License for more details.
17
 
 *
18
 
 *  You should have received a copy of the GNU General Public License
19
 
 *  along with this program; if not, write to the Free Software
20
 
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
21
 
 *
22
 
 */
23
 
 
24
 
#ifdef HAVE_CONFIG_H
25
 
#include <config.h>
26
 
#endif
27
 
 
28
 
#include <stdio.h>
29
 
#include <stdarg.h>
30
 
#include <syslog.h>
31
 
 
32
 
#include "logging.h"
33
 
 
34
 
static volatile int debug_enabled = 0;
35
 
 
36
 
static inline void vinfo(const char *format, va_list ap)
37
 
{
38
 
        vsyslog(LOG_INFO, format, ap);
39
 
}
40
 
 
41
 
void info(const char *format, ...)
42
 
{
43
 
        va_list ap;
44
 
 
45
 
        va_start(ap, format);
46
 
 
47
 
        vinfo(format, ap);
48
 
 
49
 
        va_end(ap);
50
 
}
51
 
 
52
 
void error(const char *format, ...)
53
 
{
54
 
        va_list ap;
55
 
 
56
 
        va_start(ap, format);
57
 
 
58
 
        vsyslog(LOG_ERR, format, ap);
59
 
 
60
 
        va_end(ap);
61
 
}
62
 
 
63
 
void debug(const char *format, ...)
64
 
{
65
 
        va_list ap;
66
 
 
67
 
        if (!debug_enabled)
68
 
                return;
69
 
 
70
 
        va_start(ap, format);
71
 
 
72
 
        vsyslog(LOG_DEBUG, format, ap);
73
 
 
74
 
        va_end(ap);
75
 
}
76
 
 
77
 
void toggle_debug(void)
78
 
{
79
 
        debug_enabled = (debug_enabled + 1) % 2;
80
 
}
81
 
 
82
 
void enable_debug(void)
83
 
{
84
 
        debug_enabled = 1;
85
 
}
86
 
 
87
 
void disable_debug(void)
88
 
{
89
 
        debug_enabled = 0;
90
 
}
91
 
 
92
 
void start_logging(const char *ident, const char *message, ...)
93
 
{
94
 
        va_list ap;
95
 
 
96
 
        openlog(ident, LOG_PID | LOG_NDELAY | LOG_PERROR, LOG_DAEMON);
97
 
 
98
 
        va_start(ap, message);
99
 
 
100
 
        vinfo(message, ap);
101
 
 
102
 
        va_end(ap);
103
 
}
104
 
 
105
 
void stop_logging(void)
106
 
{
107
 
        closelog();
108
 
}