change dlog output format and dlog platform logging ctrl
[framework/system/dlog.git] / include / dlog.h
1 /*
2  * Copyright (C) 2005 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 /**
17  * @file        dlog.h
18  * @version     0.4
19  * @brief       This file is the header file of interface of dlog.
20  */
21 /**
22  * @addtogroup APPLICATION_FRAMEWORK
23  * @{
24  *
25  * @defgroup dlog dlog
26  * @addtogroup dlog
27  * @{
28
29  */
30 #ifndef _DLOG_H_
31 #define _DLOG_H_
32
33 #include<stdarg.h>
34
35 #ifdef __cplusplus
36 extern "C" {
37 #endif /* __cplusplus */
38
39 /*
40  * Normally we strip LOGV (VERBOSE messages) from release builds.
41  */
42 #ifndef LOG_NDEBUG
43 #ifdef NDEBUG
44 #define LOG_NDEBUG 1
45 #else
46 #define LOG_NDEBUG 0
47 #endif
48 #endif
49
50 /*
51  * This is the local tag used for the following simplified
52  * logging macros.  You can change this preprocessor definition
53  * before using the other macros to change the tag.
54  */
55 #ifndef LOG_TAG
56 #define LOG_TAG NULL
57 #endif
58
59 #define LOG_ON() _get_logging_on()
60
61 #ifndef __MODULE__
62 #define __MODULE__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__)
63 #endif
64 /*
65  * log priority values, in ascending priority order.
66  */
67 typedef enum {
68         DLOG_UNKNOWN = 0,
69         DLOG_DEFAULT,
70         DLOG_VERBOSE,
71         DLOG_DEBUG,
72         DLOG_INFO,
73         DLOG_WARN,
74         DLOG_ERROR,
75         DLOG_FATAL,
76         DLOG_SILENT,
77 } log_priority;
78
79 typedef enum {
80     LOG_ID_MAIN = 0,
81         LOG_ID_RADIO,
82         LOG_ID_SYSTEM,
83         LOG_ID_APPS,
84         LOG_ID_MAX
85 } log_id_t;
86
87 #define CONDITION(cond)     (__builtin_expect((cond) != 0, 0))
88
89 // ---------------------------------------------------------------------
90 /**
91  * Simplified macro to send a verbose log message using the current LOG_TAG.
92  */
93 #ifndef LOGV
94 #if LOG_NDEBUG
95 #define LOGV(...)   ((void)0)
96 #else
97 #define LOGV(format, arg...) \
98         (LOG_ON() ? (LOG(LOG_VERBOSE, LOG_TAG, "%s:%s(%d)>"format, __MODULE__, __func__, __LINE__, ##arg)) : ((void)0))
99 #endif
100 #endif
101 /**
102  * Simplified macro to send a conditional verbose log message using the current LOG_TAG.
103  */
104 #ifndef LOGV_IF
105 #if LOG_NDEBUG
106 #define LOGV_IF(cond, ...)   ((void)0)
107 #else
108 #define LOGV_IF(cond, ...) \
109         (((CONDITION(cond)) && (LOG_ON())) ? \
110           (LOG(LOG_VERBOSE, LOG_TAG, "%s:%s(%d)>"format, __MODULE__, __func__, __LINE__, ##arg)) : ((void)0))
111 #endif
112 #endif
113 /**
114  * Simplified macro to send a debug log message using the current LOG_TAG.
115  */
116 #ifndef LOGD
117 #define LOGD(format, arg...) \
118         (LOG_ON() ? (LOG(LOG_DEBUG, LOG_TAG, "%s:%s(%d)>"format, __MODULE__, __func__, __LINE__, ##arg)) : ((void)0))
119 #endif
120 /**
121  * Simplified macro to send a conditional verbose log message using the current LOG_TAG.
122  */
123 #ifndef LOGD_IF
124 #define LOGD_IF(cond, ...) \
125         (((CONDITION(cond)) && (LOG_ON())) ? \
126           (LOG(LOG_DEBUG, LOG_TAG, "%s:%s(%d)>"format, __MODULE__, __func__, __LINE__, ##arg)) : ((void)0))
127 #endif
128
129 /**
130  * Simplified macro to send an info log message using the current LOG_TAG.
131  */
132 #ifndef LOGI
133 #define LOGI(format, arg...) \
134         (LOG_ON() ? (LOG(LOG_INFO, LOG_TAG, "%s:%s(%d)>"format, __MODULE__, __func__, __LINE__, ##arg)) : ((void)0))
135 #endif
136 /**
137  * Simplified macro to send a conditional verbose log message using the current LOG_TAG.
138  */
139 #ifndef LOGI_IF
140 #define LOGI_IF(cond, ...) \
141         (((CONDITION(cond)) && (LOG_ON())) ? \
142           (LOG(LOG_INFO, LOG_TAG, "%s:%s(%d)>"format, __MODULE__, __func__, __LINE__, ##arg)) : ((void)0))
143 #endif
144
145 /**
146  * Simplified macro to send a warning log message using the current LOG_TAG.
147  */
148 #ifndef LOGW
149 #define LOGW(format, arg...) \
150         (LOG_ON() ? (LOG(LOG_WARN, LOG_TAG, "%s:%s(%d)>"format, __MODULE__, __func__, __LINE__, ##arg)) : ((void)0))
151 #endif
152 /**
153  * Simplified macro to send a conditional verbose log message using the current LOG_TAG.
154  */
155 #ifndef LOGW_IF
156 #define LOGW_IF(cond, ...) \
157         (((CONDITION(cond)) && (LOG_ON())) ? \
158           (LOG(LOG_WARN, LOG_TAG, "%s:%s(%d)>"format, __MODULE__, __func__, __LINE__, ##arg)) : ((void)0))
159 #endif
160
161 /**
162  * Simplified macro to send an error log message using the current LOG_TAG.
163  */
164 #ifndef LOGE
165 #define LOGE(format, arg...) \
166         (LOG_ON() ? (LOG(LOG_ERROR, LOG_TAG, "%s:%s(%d)>"format, __MODULE__, __func__, __LINE__, ##arg)) : ((void)0))
167 #endif
168 /**
169  * Simplified macro to send a conditional verbose log message using the current LOG_TAG.
170  */
171 #ifndef LOGE_IF
172 #define LOGE_IF(cond, ...) \
173         (((CONDITION(cond)) && (LOG_ON())) ? \
174           (LOG(LOG_ERROR, LOG_TAG, "%s:%s(%d)>"format, __MODULE__, __func__, __LINE__, ##arg)) : ((void)0))
175 #endif
176 /**
177  * Simplified macro to send an error log message using the current LOG_TAG.
178  */
179 #ifndef LOGF
180 #define LOGF(format, arg...) \
181         (LOG_ON() ? (LOG(LOG_FATAL, LOG_TAG, "%s:%s(%d)>"format, __MODULE__, __func__, __LINE__, ##arg)) : ((void)0))
182 #endif
183 /**
184  * Simplified macro to send a conditional verbose log message using the current LOG_TAG.
185  */
186 #ifndef LOGF_IF
187 #define LOGF_IF(cond, ...) \
188         (((CONDITION(cond)) && (LOG_ON())) ? \
189           (LOG(LOG_FATAL, LOG_TAG, "%s:%s(%d)>"format, __MODULE__, __func__, __LINE__, ##arg)) : ((void)0))
190 #endif
191
192 // ---------------------------------------------------------------------
193 /**
194  * Simplified radio macro to send a verbose log message using the current LOG_TAG.
195  */
196 #ifndef RLOGV
197 #if LOG_NDEBUG
198 #define RLOGV(...)   ((void)0)
199 #else
200 #define RLOGV(format, arg...) \
201         (LOG_ON() ? (RLOG(LOG_VERBOSE, LOG_TAG, "%s:%s(%d)>"format, __MODULE__, __func__, __LINE__, ##arg)) : ((void)0))
202 #endif
203 #endif
204 /**
205  * Simplified radio macro to send a conditional verbose log message using the current LOG_TAG.
206  */
207 #ifndef RLOGV_IF
208 #if LOG_NDEBUG
209 #define RLOGV_IF(cond, ...)   ((void)0)
210 #else
211 #define RLOGV_IF(cond, ...) \
212         (((CONDITION(cond)) && (LOG_ON())) ? \
213           (RLOG(LOG_VERBOSE, LOG_TAG, "%s:%s(%d)>"format, __MODULE__, __func__, __LINE__, ##arg)) : ((void)0))
214 #endif
215 #endif
216
217 /**
218  * Simplified radio macro to send a debug log message using the current LOG_TAG.
219  */
220 #ifndef RLOGD
221 #define RLOGD(format, arg...) \
222         (LOG_ON() ? (RLOG(LOG_DEBUG, LOG_TAG, "%s:%s(%d)>"format, __MODULE__, __func__, __LINE__, ##arg)) : ((void)0))
223 #endif
224 /**
225  * Simplified radio macro to send a conditional verbose log message using the current LOG_TAG.
226  */
227 #ifndef RLOGD_IF
228 #define RLOGD_IF(cond, ...) \
229         (((CONDITION(cond)) && (LOG_ON())) ? \
230           (RLOG(LOG_DEBUG, LOG_TAG, "%s:%s(%d)>"format, __MODULE__, __func__, __LINE__, ##arg)) : ((void)0))
231 #endif
232
233 /**
234  * Simplified radio macro to send an info log message using the current LOG_TAG.
235  */
236 #ifndef RLOGI
237 #define RLOGI(format, arg...) \
238         (LOG_ON() ? (RLOG(LOG_INFO, LOG_TAG, "%s:%s(%d)>"format, __MODULE__, __func__, __LINE__, ##arg)) : ((void)0))
239 #endif
240 /**
241  * Simplified radio macro to send a conditional verbose log message using the current LOG_TAG.
242  */
243 #ifndef RLOGI_IF
244 #define RLOGI_IF(cond, ...) \
245         (((CONDITION(cond)) && (LOG_ON())) ? \
246           (RLOG(LOG_INFO, LOG_TAG, "%s:%s(%d)>"format, __MODULE__, __func__, __LINE__, ##arg)) : ((void)0))
247 #endif
248
249 /**
250  * Simplified radio macro to send a warning log message using the current LOG_TAG.
251  */
252 #ifndef RLOGW
253 #define RLOGW(format, arg...) \
254         (LOG_ON() ? (RLOG(LOG_WARN, LOG_TAG, "%s:%s(%d)>"format, __MODULE__, __func__, __LINE__, ##arg)) : ((void)0))
255 #endif
256 /**
257  * Simplified radio macro to send a conditional verbose log message using the current LOG_TAG.
258  */
259 #ifndef RLOGW_IF
260 #define RLOGW_IF(cond, ...) \
261         (((CONDITION(cond)) && (LOG_ON())) ? \
262           (RLOG(LOG_WARN, LOG_TAG, "%s:%s(%d)>"format, __MODULE__, __func__, __LINE__, ##arg)) : ((void)0))
263 #endif
264
265 /**
266  * Simplified radio macro to send an error log message using the current LOG_TAG.
267  */
268 #ifndef RLOGE
269 #define RLOGE(format, arg...) \
270         (LOG_ON() ? (RLOG(LOG_ERROR, LOG_TAG, "%s:%s(%d)>"format, __MODULE__, __func__, __LINE__, ##arg)) : ((void)0))
271 #endif
272 /**
273  * Simplified radio macro to send a conditional verbose log message using the current LOG_TAG.
274  */
275 #ifndef RLOGE_IF
276 #define RLOGE_IF(cond, ...) \
277         (((CONDITION(cond)) && (LOG_ON())) ? \
278           (RLOG(LOG_ERROR, LOG_TAG, "%s:%s(%d)>"format, __MODULE__, __func__, __LINE__, ##arg)) : ((void)0))
279 #endif
280 /**
281  * Simplified radio macro to send an error log message using the current LOG_TAG.
282  */
283 #ifndef RLOGF
284 #define RLOGF(format, arg...) \
285         (LOG_ON() ? (RLOG(LOG_FATAL, LOG_TAG, "%s:%s(%d)>"format, __MODULE__, __func__, __LINE__, ##arg)) : ((void)0))
286 #endif
287 /**
288  * Simplified radio macro to send a conditional verbose log message using the current LOG_TAG.
289  */
290 #ifndef RLOGF_IF
291 #define RLOGF_IF(cond, ...) \
292         (((CONDITION(cond)) && (LOG_ON())) ? \
293           (RLOG(LOG_FATAL, LOG_TAG, "%s:%s(%d)>"format, __MODULE__, __func__, __LINE__, ##arg)) : ((void)0))
294 #endif
295
296
297 // ---------------------------------------------------------------------
298 /**
299  * Simplified system macro to send a verbose log message using the current LOG_TAG.
300  */
301 #ifndef SLOGV
302 #if LOG_NDEBUG
303 #define SLOGV(...)   ((void)0)
304 #else
305 #define SLOGV(format, arg...) \
306         (LOG_ON() ? (SLOG(LOG_VERBOSE, LOG_TAG, "%s:%s(%d)>"format, __MODULE__, __func__, __LINE__, ##arg)) : ((void)0))
307 #endif
308 #endif
309 /**
310  * Simplified macro to send a conditional verbose log message using the current LOG_TAG.
311  */
312 #ifndef SLOGV_IF
313 #if LOG_NDEBUG
314 #define SLOGV_IF(cond, ...)   ((void)0)
315 #else
316 #define SLOGV_IF(cond, ...) \
317         (((CONDITION(cond)) && (LOG_ON())) ? \
318           (SLOG(LOG_VERBOSE, LOG_TAG, "%s:%s(%d)>"format, __MODULE__, __func__, __LINE__, ##arg)) : ((void)0))
319 #endif
320 #endif
321
322 /**
323  * Simplified system macro to send a debug log message using the current LOG_TAG.
324  */
325 #ifndef SLOGD
326 #define SLOGD(format, arg...) \
327         (LOG_ON() ? (SLOG(LOG_DEBUG, LOG_TAG, "%s:%s(%d)>"format, __MODULE__, __func__, __LINE__, ##arg)) : ((void)0))
328 #endif
329 /**
330  * Simplified system macro to send a conditional verbose log message using the current LOG_TAG.
331  */
332 #ifndef SLOGD_IF
333 #define SLOGD_IF(cond, ...) \
334         (((CONDITION(cond)) && (LOG_ON())) ? \
335           (SLOG(LOG_DEBUG, LOG_TAG, "%s:%s(%d)>"format, __MODULE__, __func__, __LINE__, ##arg)) : ((void)0))
336 #endif
337
338 /**
339  * Simplified system macro to send an info log message using the current LOG_TAG.
340  */
341 #ifndef SLOGI
342 #define SLOGI(format, arg...) \
343         (LOG_ON() ? (SLOG(LOG_INFO, LOG_TAG, "%s:%s(%d)>"format, __MODULE__, __func__, __LINE__, ##arg)) : ((void)0))
344 #endif
345 /**
346  * Simplified system macro to send a conditional verbose log message using the current LOG_TAG.
347  */
348 #ifndef SLOGI_IF
349 #define SLOGI_IF(cond, ...) \
350         (((CONDITION(cond)) && (LOG_ON())) ? \
351           (SLOG(LOG_INFO, LOG_TAG, "%s:%s(%d)>"format, __MODULE__, __func__, __LINE__, ##arg)) : ((void)0))
352 #endif
353
354 /**
355  * Simplified system macro to send a warning log message using the current LOG_TAG.
356  */
357 #ifndef SLOGW
358 #define SLOGW(format, arg...) \
359         (LOG_ON() ? (SLOG(LOG_WARN, LOG_TAG, "%s:%s(%d)>"format, __MODULE__, __func__, __LINE__, ##arg)) : ((void)0))
360 #endif
361 /**
362  * Simplified system macro to send a conditional verbose log message using the current LOG_TAG.
363  */
364 #ifndef SLOGW_IF
365 #define SLOGW_IF(cond, ...) \
366         (((CONDITION(cond)) && (LOG_ON())) ? \
367           (SLOG(LOG_WARN, LOG_TAG, "%s:%s(%d)>"format, __MODULE__, __func__, __LINE__, ##arg)) : ((void)0))
368 #endif
369
370 /**
371  * Simplified system macro to send an error log message using the current LOG_TAG.
372  */
373 #ifndef SLOGE
374 #define SLOGE(format, arg...) \
375         (LOG_ON() ? (SLOG(LOG_ERROR, LOG_TAG, "%s:%s(%d)>"format, __MODULE__, __func__, __LINE__, ##arg)) : ((void)0))
376 #endif
377 /**
378  * Simplified system macro to send a conditional verbose log message using the current LOG_TAG.
379  */
380 #ifndef SLOGE_IF
381 #define SLOGE_IF(cond, ...) \
382         (((CONDITION(cond)) && (LOG_ON())) ? \
383           (SLOG(LOG_ERROR, LOG_TAG, "%s:%s(%d)>"format, __MODULE__, __func__, __LINE__, ##arg)) : ((void)0))
384 #endif
385 /**
386  * Simplified system macro to send an error log message using the current LOG_TAG.
387  */
388 #ifndef SLOGF
389 #define SLOGF(format, arg...) \
390         (LOG_ON() ? (SLOG(LOG_FATAL, LOG_TAG, "%s:%s(%d)>"format, __MODULE__, __func__, __LINE__, ##arg)) : ((void)0))
391 #endif
392 /**
393  * Simplified system macro to send a conditional verbose log message using the current LOG_TAG.
394  */
395 #ifndef SLOGF_IF
396 #define SLOGF_IF(cond, ...) \
397         (((CONDITION(cond)) && (LOG_ON())) ? \
398           (SLOG(LOG_FATAL, LOG_TAG, "%s:%s(%d)>"format, __MODULE__, __func__, __LINE__, ##arg)) : ((void)0))
399 #endif
400
401 // ---------------------------------------------------------------------
402
403 /**
404  * Simplified macro to send a verbose log message using the current LOG_TAG.
405  */
406 #ifndef ALOGV
407 #if LOG_NDEBUG
408 #define ALOGV(...)   ((void)0)
409 #else
410 #define ALOGV(...) ((void)ALOG(LOG_VERBOSE, LOG_TAG, __VA_ARGS__))
411 #endif
412 #endif
413 /**
414  * Simplified macro to send a debug log message using the current LOG_TAG.
415  */
416 #ifndef ALOGD
417 #define ALOGD(...) ((void)ALOG(LOG_DEBUG, LOG_TAG, __VA_ARGS__))
418 #endif
419 /**
420  * Simplified macro to send an info log message using the current LOG_TAG.
421  */
422 #ifndef ALOGI
423 #define ALOGI(...) ((void)ALOG(LOG_INFO, LOG_TAG, __VA_ARGS__))
424 #endif
425 /**
426  * Simplified macro to send a warning log message using the current LOG_TAG.
427  */
428 #ifndef ALOGW
429 #define ALOGW(...) ((void)ALOG(LOG_WARN, LOG_TAG, __VA_ARGS__))
430 #endif
431 /**
432  * Simplified macro to send an error log message using the current LOG_TAG.
433  */
434 #ifndef ALOGE
435 #define ALOGE(...) ((void)ALOG(LOG_ERROR, LOG_TAG, __VA_ARGS__))
436 #endif
437
438 // ---------------------------------------------------------------------
439 /**
440  * Basic log message macro that allows you to specify a priority and a tag
441  *
442  * Example:
443  *  LOG(DLOG_WARN, NULL, "Failed with error %d", errno);
444  *
445  * The second argument may be NULL or "" to indicate the "global" tag.
446  * 
447  * Future work : we want to put filename and line number automatically only when debug build mode 
448  */
449 #ifndef LOG
450 #define LOG(priority, tag, ...) \
451         print_log(D##priority, tag, __VA_ARGS__)
452 #endif
453
454 /**
455  * tizen app log macro that allows you to specify a priority and a tag.
456  */
457 #ifndef ALOG
458 #define ALOG(priority, tag, ...) \
459         print_apps_log(D##priority, tag, __VA_ARGS__)
460 #endif
461 /**
462  * Basic radio log macro that allows you to specify a priority and a tag.
463  */
464 #ifndef RLOG
465 #define RLOG(priority, tag, ...) \
466         print_radio_log(D##priority, tag, __VA_ARGS__)
467 #endif
468 /**
469  * Basic system log macro that allows you to specify a priority and a tag.
470  */
471 #ifndef SLOG
472 #define SLOG(priority, tag, ...) \
473     print_system_log(D##priority, tag, __VA_ARGS__)
474 #endif
475
476 /*
477  * ===========================================================================
478  *
479  * The stuff in the rest of this file should not be used directly.
480  */
481
482 #define print_apps_log(prio, tag, fmt...) \
483         __dlog_print(LOG_ID_APPS, prio, tag, fmt)
484
485 #define print_log(prio, tag, fmt...) \
486         __dlog_print(LOG_ID_MAIN, prio, tag, fmt)
487
488 #define print_radio_log(prio, tag, fmt...)\
489         __dlog_print(LOG_ID_RADIO, prio, tag, fmt)
490
491 #define print_system_log(prio, tag, fmt...)\
492         __dlog_print(LOG_ID_SYSTEM, prio, tag, fmt)
493
494 /**
495  * @brief               send log. must specify log_id ,priority, tag and format string.
496  * @pre         none
497  * @post                none
498  * @see         __dlog_print
499  * @remarks     you must not use this API directly. use macros instead.
500  * @param[in]   log_id  log device id
501  * @param[in]   prio    priority
502  * @param[in]   tag     tag
503  * @param[in]   fmt     format string 
504  * @return                      Operation result
505  * @retval              0>=     Success
506  * @retval              -1      Error
507  * @code
508 // you have to use LOG(), SLOG(), RLOG() family not to use __dlog_print() directly
509 // so below example is just for passing Documentation Verification !!!
510 #define LOG_TAG USR_TAG
511 #include<dlog.h>
512  __dlog_print(LOG_ID_MAIN, DLOG_INFO, USR_TAG, "you must not use this API directly");
513  * @endcode
514  */
515 int __dlog_print(log_id_t log_id, int prio, const char *tag, const char *fmt, ...);
516 int __dlog_vprint(log_id_t log_id, int prio, const char *tag, const char *fmt, va_list ap);
517 int _get_logging_on();
518
519 #ifdef __cplusplus
520 }
521 #endif /* __cplusplus */
522
523
524 /** @} */
525 /** @} */
526
527 #endif /* _DLOG_H_*/
528