Add function for printing warnings
[framework/connectivity/connman.git] / src / log.c
1 /*
2  *
3  *  Connection Manager
4  *
5  *  Copyright (C) 2007-2009  Intel Corporation. All rights reserved.
6  *
7  *  This program is free software; you can redistribute it and/or modify
8  *  it under the terms of the GNU General Public License version 2 as
9  *  published by the Free Software Foundation.
10  *
11  *  This program is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  *  GNU General Public License for more details.
15  *
16  *  You should have received a copy of the GNU General Public License
17  *  along with this program; if not, write to the Free Software
18  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19  *
20  */
21
22 #ifdef HAVE_CONFIG_H
23 #include <config.h>
24 #endif
25
26 #include <stdarg.h>
27 #include <syslog.h>
28
29 #include "connman.h"
30
31 static volatile gboolean debug_enabled = FALSE;
32
33 /**
34  * connman_info:
35  * @format: format string
36  * @Varargs: list of arguments
37  *
38  * Output general information
39  */
40 void connman_info(const char *format, ...)
41 {
42         va_list ap;
43
44         va_start(ap, format);
45
46         vsyslog(LOG_INFO, format, ap);
47
48         va_end(ap);
49 }
50
51 /**
52  * connman_warn:
53  * @format: format string
54  * @Varargs: list of arguments
55  *
56  * Output warning messages
57  */
58 void connman_warn(const char *format, ...)
59 {
60         va_list ap;
61
62         va_start(ap, format);
63
64         vsyslog(LOG_WARNING, format, ap);
65
66         va_end(ap);
67 }
68
69 /**
70  * connman_error:
71  * @format: format string
72  * @varargs: list of arguments
73  *
74  * Output error messages
75  */
76 void connman_error(const char *format, ...)
77 {
78         va_list ap;
79
80         va_start(ap, format);
81
82         vsyslog(LOG_ERR, format, ap);
83
84         va_end(ap);
85 }
86
87 /**
88  * connman_debug:
89  * @format: format string
90  * @varargs: list of arguments
91  *
92  * Output debug message
93  *
94  * The actual output of the debug message is controlled via a command line
95  * switch. If not enabled, these messages will be ignored.
96  */
97 void connman_debug(const char *format, ...)
98 {
99         va_list ap;
100
101         if (debug_enabled == FALSE)
102                 return;
103
104         va_start(ap, format);
105
106         vsyslog(LOG_DEBUG, format, ap);
107
108         va_end(ap);
109 }
110
111 void __connman_toggle_debug(void)
112 {
113         if (debug_enabled == TRUE) {
114                 connman_info("Disabling debug output");
115                 debug_enabled = FALSE;
116         } else {
117                 connman_info("Enabling debug output");
118                 debug_enabled = TRUE;
119         }
120 }
121
122 int __connman_log_init(gboolean detach, gboolean debug)
123 {
124         int option = LOG_NDELAY | LOG_PID;
125
126         if (detach == FALSE)
127                 option |= LOG_PERROR;
128
129         openlog("connmand", option, LOG_DAEMON);
130
131         syslog(LOG_INFO, "Connection Manager version %s", VERSION);
132
133         if (debug == TRUE)
134                 __connman_toggle_debug();
135
136         return 0;
137 }
138
139 void __connman_log_cleanup(void)
140 {
141         syslog(LOG_INFO, "Exit");
142
143         closelog();
144 }
145
146 gboolean __connman_debug_enabled(void)
147 {
148         return debug_enabled;
149 }