-
Notifications
You must be signed in to change notification settings - Fork 41
/
ossolog.h
299 lines (258 loc) · 11.8 KB
/
ossolog.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
/*
* ossolog.h
* peer
*
* Created by Matias Piipari on 21/12/2010.
* Copyright 2010 __MyCompanyName__. All rights reserved.
*
*/
/**
@file osso-log.h
The OSSO logging macros. Version: 20 Mar 2005.
<p>
Macro definitions that have an effect to the logging macros:
DEBUG, OSSOLOG_COMPILE Whether to compile the macros
(prefer OSSOLOG_COMPILE over DEBUG)
OSSOLOG_STDOUT All logging to stdout(*
OSSOLOG_STDERR All logging to stderr(*
*) No timestamp nor file name.
To see the logging output of D-Bus-activated programs, define
DBUS_DEBUG_OUTPUT environment variable for the D-Bus daemon and
define the OSSOLOG_STDERR macro at compile time.
Note that these macros are provided because Glib logging does not
currently allow stripping the logging function calls away at
compile time.
---
This file is part of libosso.
Copyright (C) 2004-2005 Nokia Corporation. All rights reserved.
Contact: Kimmo H�m�l�inen <[email protected]>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public License
version 2.1 as published by the Free Software Foundation.
This library is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
02110-1301 USA
*/
#ifndef OSSO_LOG_H
#define OSSO_LOG_H
#ifdef DEBUG
#define OSSOLOG_COMPILE
#endif
#ifdef OSSOLOG_COMPILE
#if defined OSSOLOG_STDOUT || defined OSSOLOG_STDERR
#include <stdio.h> /* printf(), fprintf() */
#else
#include <syslog.h> /* syslog(), openlog(), closelog() */
#endif
#endif
/*** the macros ***/
#ifdef OSSOLOG_COMPILE
/* the binary has logging compiled in */
#if !defined OSSOLOG_STDOUT && !defined OSSOLOG_STDERR
/* log to the syslog */
#define ULOG_CRIT(...) syslog(LOG_CRIT | LOG_USER, __VA_ARGS__)
#define ULOG_ERR(...) syslog(LOG_ERR | LOG_USER, __VA_ARGS__)
#define ULOG_WARN(...) syslog(LOG_WARNING | LOG_USER, __VA_ARGS__)
#define ULOG_INFO(...) syslog(LOG_INFO | LOG_USER, __VA_ARGS__)
#define ULOG_DEBUG(...) syslog(LOG_DEBUG | LOG_USER, __VA_ARGS__)
#define ULOG_CRIT_L(FMT, ARG...) syslog(LOG_CRIT | LOG_USER, \
"%s:%d: " FMT, __FILE__, __LINE__, ## ARG)
#define ULOG_ERR_L(FMT, ARG...) syslog(LOG_ERR | LOG_USER, \
"%s:%d: " FMT, __FILE__, __LINE__, ## ARG)
#define ULOG_WARN_L(FMT, ARG...) syslog(LOG_WARNING | LOG_USER, \
"%s:%d: " FMT, __FILE__, __LINE__, ## ARG)
#define ULOG_INFO_L(FMT, ARG...) syslog(LOG_INFO | LOG_USER, \
"%s:%d: " FMT, __FILE__, __LINE__, ## ARG)
#define ULOG_DEBUG_L(FMT, ARG...) syslog(LOG_DEBUG | LOG_USER, \
"%s:%d: " FMT, __FILE__, __LINE__, ## ARG)
#define ULOG_CRIT_F(FMT, ARG...) syslog(LOG_CRIT | LOG_USER, \
"%s:%d: " FMT, __FUNCTION__, __LINE__, ## ARG)
#define ULOG_ERR_F(FMT, ARG...) syslog(LOG_ERR | LOG_USER, \
"%s:%d: " FMT, __FUNCTION__, __LINE__, ## ARG)
#define ULOG_WARN_F(FMT, ARG...) syslog(LOG_WARNING | LOG_USER, \
"%s:%d: " FMT, __FUNCTION__, __LINE__, ## ARG)
#define ULOG_INFO_F(FMT, ARG...) syslog(LOG_INFO | LOG_USER, \
"%s:%d: " FMT, __FUNCTION__, __LINE__, ## ARG)
#define ULOG_DEBUG_F(FMT, ARG...) syslog(LOG_DEBUG | LOG_USER, \
"%s:%d: " FMT, __FUNCTION__, __LINE__, ## ARG)
#define DLOG_CRIT(...) syslog(LOG_CRIT | LOG_DAEMON, __VA_ARGS__)
#define DLOG_ERR(...) syslog(LOG_ERR | LOG_DAEMON, __VA_ARGS__)
#define DLOG_WARN(...) syslog(LOG_WARNING | LOG_DAEMON, __VA_ARGS__)
#define DLOG_INFO(...) syslog(LOG_INFO | LOG_DAEMON, __VA_ARGS__)
#define DLOG_DEBUG(...) syslog(LOG_DEBUG | LOG_DAEMON, __VA_ARGS__)
#define DLOG_CRIT_L(FMT, ARG...) syslog(LOG_CRIT | LOG_DAEMON, \
"%s:%d: " FMT, __FILE__, __LINE__, ## ARG)
#define DLOG_ERR_L(FMT, ARG...) syslog(LOG_ERR | LOG_DAEMON, \
"%s:%d: " FMT, __FILE__, __LINE__, ## ARG)
#define DLOG_WARN_L(FMT, ARG...) syslog(LOG_WARNING | LOG_DAEMON, \
"%s:%d: " FMT, __FILE__, __LINE__, ## ARG)
#define DLOG_INFO_L(FMT, ARG...) syslog(LOG_INFO | LOG_DAEMON, \
"%s:%d: " FMT, __FILE__, __LINE__, ## ARG)
#define DLOG_DEBUG_L(FMT, ARG...) syslog(LOG_DEBUG | LOG_DAEMON, \
"%s:%d: " FMT, __FILE__, __LINE__, ## ARG)
#define DLOG_CRIT_F(FMT, ARG...) syslog(LOG_CRIT | LOG_DAEMON, \
"%s:%d: " FMT, __FUNCTION__, __LINE__, ## ARG)
#define DLOG_ERR_F(FMT, ARG...) syslog(LOG_ERR | LOG_DAEMON, \
"%s:%d: " FMT, __FUNCTION__, __LINE__, ## ARG)
#define DLOG_WARN_F(FMT, ARG...) syslog(LOG_WARNING | LOG_DAEMON, \
"%s:%d: " FMT, __FUNCTION__, __LINE__, ## ARG)
#define DLOG_INFO_F(FMT, ARG...) syslog(LOG_INFO | LOG_DAEMON, \
"%s:%d: " FMT, __FUNCTION__, __LINE__, ## ARG)
#define DLOG_DEBUG_F(FMT, ARG...) syslog(LOG_DEBUG | LOG_DAEMON, \
"%s:%d: " FMT, __FUNCTION__, __LINE__, ## ARG)
#define ULOG_OPEN(X) openlog(X, LOG_PID | LOG_NDELAY, LOG_USER)
#define DLOG_OPEN(X) openlog(X, LOG_PID | LOG_NDELAY, LOG_DAEMON)
#define LOG_CLOSE() closelog()
#elif defined OSSOLOG_STDOUT
/* log to the stdout */
#define ULOG_CRIT(...) (printf(__VA_ARGS__),printf("\n"))
#define ULOG_ERR(...) (printf(__VA_ARGS__),printf("\n"))
#define ULOG_WARN(...) (printf(__VA_ARGS__),printf("\n"))
#define ULOG_INFO(...) (printf(__VA_ARGS__),printf("\n"))
#define ULOG_DEBUG(...) (printf(__VA_ARGS__),printf("\n"))
#define ULOG_CRIT_L(FMT, ARG...) printf(\
"%s:%d: " FMT "\n", __FILE__, __LINE__, ## ARG)
#define ULOG_ERR_L(FMT, ARG...) printf(\
"%s:%d: " FMT "\n", __FILE__, __LINE__, ## ARG)
#define ULOG_WARN_L(FMT, ARG...) printf(\
"%s:%d: " FMT "\n", __FILE__, __LINE__, ## ARG)
#define ULOG_INFO_L(FMT, ARG...) printf(\
"%s:%d: " FMT "\n", __FILE__, __LINE__, ## ARG)
#define ULOG_DEBUG_L(FMT, ARG...) printf(\
"%s:%d: " FMT "\n", __FILE__, __LINE__, ## ARG)
#define ULOG_CRIT_F(FMT, ARG...) printf(\
"%s:%d: " FMT "\n", __FUNCTION__, __LINE__, ## ARG)
#define ULOG_ERR_F(FMT, ARG...) printf(\
"%s:%d: " FMT "\n", __FUNCTION__, __LINE__, ## ARG)
#define ULOG_WARN_F(FMT, ARG...) printf(\
"%s:%d: " FMT "\n", __FUNCTION__, __LINE__, ## ARG)
#define ULOG_INFO_F(FMT, ARG...) printf(\
"%s:%d: " FMT "\n", __FUNCTION__, __LINE__, ## ARG)
#define ULOG_DEBUG_F(FMT, ARG...) printf(\
"%s:%d: " FMT "\n", __FUNCTION__, __LINE__, ## ARG)
#define DLOG_CRIT(...) (printf(__VA_ARGS__),printf("\n"))
#define DLOG_ERR(...) (printf(__VA_ARGS__),printf("\n"))
#define DLOG_WARN(...) (printf(__VA_ARGS__),printf("\n"))
#define DLOG_INFO(...) (printf(__VA_ARGS__),printf("\n"))
#define DLOG_DEBUG(...) (printf(__VA_ARGS__),printf("\n"))
#define DLOG_CRIT_L(FMT, ARG...) printf(\
"%s:%d: " FMT "\n", __FILE__, __LINE__, ## ARG)
#define DLOG_ERR_L(FMT, ARG...) printf(\
"%s:%d: " FMT "\n", __FILE__, __LINE__, ## ARG)
#define DLOG_WARN_L(FMT, ARG...) printf(\
"%s:%d: " FMT "\n", __FILE__, __LINE__, ## ARG)
#define DLOG_INFO_L(FMT, ARG...) printf(\
"%s:%d: " FMT "\n", __FILE__, __LINE__, ## ARG)
#define DLOG_DEBUG_L(FMT, ARG...) printf(\
"%s:%d: " FMT "\n", __FILE__, __LINE__, ## ARG)
#define DLOG_CRIT_F(FMT, ARG...) printf(\
"%s:%d: " FMT "\n", __FUNCTION__, __LINE__, ## ARG)
#define DLOG_ERR_F(FMT, ARG...) printf(\
"%s:%d: " FMT "\n", __FUNCTION__, __LINE__, ## ARG)
#define DLOG_WARN_F(FMT, ARG...) printf(\
"%s:%d: " FMT "\n", __FUNCTION__, __LINE__, ## ARG)
#define DLOG_INFO_F(FMT, ARG...) printf(\
"%s:%d: " FMT "\n", __FUNCTION__, __LINE__, ## ARG)
#define DLOG_DEBUG_F(FMT, ARG...) printf(\
"%s:%d: " FMT "\n", __FUNCTION__, __LINE__, ## ARG)
#define ULOG_OPEN(X) do {} while (0)
#define DLOG_OPEN(X) do {} while (0)
#define LOG_CLOSE() do {} while (0)
#else
/* log to the stderr */
#define ULOG_CRIT(...) (fprintf(stderr, __VA_ARGS__),fprintf(stderr, "\n"))
#define ULOG_ERR(...) (fprintf(stderr, __VA_ARGS__),fprintf(stderr, "\n"))
#define ULOG_WARN(...) (fprintf(stderr, __VA_ARGS__),fprintf(stderr, "\n"))
#define ULOG_INFO(...) (fprintf(stderr, __VA_ARGS__),fprintf(stderr, "\n"))
#define ULOG_DEBUG(...) (fprintf(stderr, __VA_ARGS__),fprintf(stderr, "\n"))
#define ULOG_CRIT_L(FMT, ARG...) fprintf(stderr, \
"%s:%d: " FMT "\n", __FILE__, __LINE__, ## ARG)
#define ULOG_ERR_L(FMT, ARG...) fprintf(stderr, \
"%s:%d: " FMT "\n", __FILE__, __LINE__, ## ARG)
#define ULOG_WARN_L(FMT, ARG...) fprintf(stderr, \
"%s:%d: " FMT "\n", __FILE__, __LINE__, ## ARG)
#define ULOG_INFO_L(FMT, ARG...) fprintf(stderr, \
"%s:%d: " FMT "\n", __FILE__, __LINE__, ## ARG)
#define ULOG_DEBUG_L(FMT, ARG...) fprintf(stderr, \
"%s:%d: " FMT "\n", __FILE__, __LINE__, ## ARG)
#define ULOG_CRIT_F(FMT, ARG...) fprintf(stderr, \
"%s:%d: " FMT "\n", __FUNCTION__, __LINE__, ## ARG)
#define ULOG_ERR_F(FMT, ARG...) fprintf(stderr, \
"%s:%d: " FMT "\n", __FUNCTION__, __LINE__, ## ARG)
#define ULOG_WARN_F(FMT, ARG...) fprintf(stderr, \
"%s:%d: " FMT "\n", __FUNCTION__, __LINE__, ## ARG)
#define ULOG_INFO_F(FMT, ARG...) fprintf(stderr, \
"%s:%d: " FMT "\n", __FUNCTION__, __LINE__, ## ARG)
#define ULOG_DEBUG_F(FMT, ARG...) fprintf(stderr, \
"%s:%d: " FMT "\n", __FUNCTION__, __LINE__, ## ARG)
#define DLOG_CRIT(...) (fprintf(stderr, __VA_ARGS__),fprintf(stderr, "\n"))
#define DLOG_ERR(...) (fprintf(stderr, __VA_ARGS__),fprintf(stderr, "\n"))
#define DLOG_WARN(...) (fprintf(stderr, __VA_ARGS__),fprintf(stderr, "\n"))
#define DLOG_INFO(...) (fprintf(stderr, __VA_ARGS__),fprintf(stderr, "\n"))
#define DLOG_DEBUG(...) (fprintf(stderr, __VA_ARGS__),fprintf(stderr, "\n"))
#define DLOG_CRIT_L(FMT, ARG...) fprintf(stderr, \
"%s:%d: " FMT "\n", __FILE__, __LINE__, ## ARG)
#define DLOG_ERR_L(FMT, ARG...) fprintf(stderr, \
"%s:%d: " FMT "\n", __FILE__, __LINE__, ## ARG)
#define DLOG_WARN_L(FMT, ARG...) fprintf(stderr, \
"%s:%d: " FMT "\n", __FILE__, __LINE__, ## ARG)
#define DLOG_INFO_L(FMT, ARG...) fprintf(stderr, \
"%s:%d: " FMT "\n", __FILE__, __LINE__, ## ARG)
#define DLOG_DEBUG_L(FMT, ARG...) fprintf(stderr, \
"%s:%d: " FMT "\n", __FILE__, __LINE__, ## ARG)
#define DLOG_CRIT_F(FMT, ARG...) fprintf(stderr, \
"%s:%d: " FMT "\n", __FUNCTION__, __LINE__, ## ARG)
#define DLOG_ERR_F(FMT, ARG...) fprintf(stderr, \
"%s:%d: " FMT "\n", __FUNCTION__, __LINE__, ## ARG)
#define DLOG_WARN_F(FMT, ARG...) fprintf(stderr, \
"%s:%d: " FMT "\n", __FUNCTION__, __LINE__, ## ARG)
#define DLOG_INFO_F(FMT, ARG...) fprintf(stderr, \
"%s:%d: " FMT "\n", __FUNCTION__, __LINE__, ## ARG)
#define DLOG_DEBUG_F(FMT, ARG...) fprintf(stderr, \
"%s:%d: " FMT "\n", __FUNCTION__, __LINE__, ## ARG)
#define ULOG_OPEN(X) do {} while (0)
#define DLOG_OPEN(X) do {} while (0)
#define LOG_CLOSE() do {} while (0)
#endif /* !defined OSSOLOG_STDOUT && !defined OSSOLOG_STDERR */
#else
/* no logging is compiled to the binary */
#define ULOG_CRIT(...) do {} while (0)
#define ULOG_ERR(...) do {} while (0)
#define ULOG_WARN(...) do {} while (0)
#define ULOG_INFO(...) do {} while (0)
#define ULOG_DEBUG(...) do {} while (0)
#define ULOG_CRIT_L(...) do {} while (0)
#define ULOG_ERR_L(...) do {} while (0)
#define ULOG_WARN_L(...) do {} while (0)
#define ULOG_INFO_L(...) do {} while (0)
#define ULOG_DEBUG_L(...) do {} while (0)
#define ULOG_CRIT_F(...) do {} while (0)
#define ULOG_ERR_F(...) do {} while (0)
#define ULOG_WARN_F(...) do {} while (0)
#define ULOG_INFO_F(...) do {} while (0)
#define ULOG_DEBUG_F(...) do {} while (0)
#define DLOG_CRIT(...) do {} while (0)
#define DLOG_ERR(...) do {} while (0)
#define DLOG_WARN(...) do {} while (0)
#define DLOG_INFO(...) do {} while (0)
#define DLOG_DEBUG(...) do {} while (0)
#define DLOG_CRIT_L(...) do {} while (0)
#define DLOG_ERR_L(...) do {} while (0)
#define DLOG_WARN_L(...) do {} while (0)
#define DLOG_INFO_L(...) do {} while (0)
#define DLOG_DEBUG_L(...) do {} while (0)
#define DLOG_CRIT_F(...) do {} while (0)
#define DLOG_ERR_F(...) do {} while (0)
#define DLOG_WARN_F(...) do {} while (0)
#define DLOG_INFO_F(...) do {} while (0)
#define DLOG_DEBUG_F(...) do {} while (0)
#define ULOG_OPEN(X) do {} while (0)
#define DLOG_OPEN(X) do {} while (0)
#define LOG_CLOSE() do {} while (0)
#endif /* OSSOLOG_COMPILE */
#endif /* OSSO_LOG_H */