tizen_2.0 merged
[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
18 /** 
19  * @file        dlog.h
20  * @version     0.4
21  * @brief       This file is the header file of interface of dlog.
22  */
23
24
25 /**
26  * @addtogroup APPLICATION_FRAMEWORK
27  * @{
28  *
29  * @defgroup dlog dlog
30  * @addtogroup dlog
31  * @{
32
33  */
34
35
36 #ifndef _DLOG_H_
37 #define _DLOG_H_
38
39 #include<stdarg.h>
40
41 #ifdef __cplusplus
42 extern "C" {
43 #endif /* __cplusplus */
44
45 /*
46  * Normally we strip LOGV (VERBOSE messages) from release builds.
47  */
48 #ifndef LOG_NDEBUG
49 #ifdef NDEBUG
50 #define LOG_NDEBUG 1
51 #else
52 #define LOG_NDEBUG 0
53 #endif
54 #endif
55
56 /*
57  * This is the local tag used for the following simplified
58  * logging macros.  You can change this preprocessor definition
59  * before using the other macros to change the tag.
60  */
61 #ifndef LOG_TAG
62 #define LOG_TAG NULL
63 #endif
64
65 /*
66  * log priority values, in ascending priority order.
67  */
68 typedef enum {
69         DLOG_UNKNOWN = 0,
70         DLOG_DEFAULT,
71         DLOG_VERBOSE,
72         DLOG_DEBUG,
73         DLOG_INFO,
74         DLOG_WARN,
75         DLOG_ERROR,
76         DLOG_FATAL,
77         DLOG_SILENT,
78 } log_priority;
79
80 typedef enum {
81     LOG_ID_MAIN = 0,
82     LOG_ID_RADIO,
83     LOG_ID_SYSTEM,
84     LOG_ID_APPS,
85     LOG_ID_MAX
86 } log_id_t;
87
88 #define CONDITION(cond)     (__builtin_expect((cond)!=0, 0))
89
90 // ---------------------------------------------------------------------
91
92 /**
93  * Simplified macro to send a verbose log message using the current LOG_TAG.
94  */
95 #ifndef LOGV
96 #if LOG_NDEBUG
97 #define LOGV(...)   ((void)0)
98 #else
99 #define LOGV(...) ((void)LOG(LOG_VERBOSE, LOG_TAG, __VA_ARGS__))
100
101 #endif
102 #endif
103
104 /**
105  * Simplified macro to send a conditional verbose log message using the current LOG_TAG.
106  */
107 #ifndef LOGV_IF
108 #if LOG_NDEBUG
109 #define LOGV_IF(cond, ...)   ((void)0)
110 #else
111 #define LOGV_IF(cond, ...) \
112     ( (CONDITION(cond)) \
113     ? ((void)LOG(LOG_VERBOSE, LOG_TAG, __VA_ARGS__)) \
114     : (void)0 )
115 #endif
116 #endif
117
118 /**
119  * Simplified macro to send a debug log message using the current LOG_TAG.
120  */
121 #ifndef LOGD
122 #define LOGD(...) ((void)LOG(LOG_DEBUG, LOG_TAG, __VA_ARGS__))
123 #endif
124
125 /**
126  * Simplified macro to send a conditional debug log message using the current LOG_TAG.
127  */
128 #ifndef LOGD_IF
129 #define LOGD_IF(cond, ...) \
130     ( (CONDITION(cond)) \
131     ? ((void)LOG(LOG_DEBUG, LOG_TAG, __VA_ARGS__)) \
132     : (void)0 )
133 #endif
134
135 /**
136  * Simplified macro to send an info log message using the current LOG_TAG.
137  */
138 #ifndef LOGI
139 #define LOGI(...) ((void)LOG(LOG_INFO, LOG_TAG, __VA_ARGS__))
140 #endif
141
142 /**
143  * Simplified macro to send a conditional info log message using the current LOG_TAG.
144  */
145 #ifndef LOGI_IF
146 #define LOGI_IF(cond, ...) \
147     ( (CONDITION(cond)) \
148     ? ((void)LOG(LOG_INFO, LOG_TAG, __VA_ARGS__)) \
149     : (void)0 )
150 #endif
151
152 /**
153  * Simplified macro to send a warning log message using the current LOG_TAG.
154  */
155 #ifndef LOGW
156 #define LOGW(...) ((void)LOG(LOG_WARN, LOG_TAG, __VA_ARGS__))
157 #endif
158
159 /**
160  * Simplified macro to send a conditional warning log message using the current LOG_TAG.
161  */
162 #ifndef LOGW_IF
163 #define LOGW_IF(cond, ...) \
164     ( (CONDITION(cond)) \
165     ? ((void)LOG(LOG_WARN, LOG_TAG, __VA_ARGS__)) \
166     : (void)0 )
167 #endif
168
169 /**
170  * Simplified macro to send an error log message using the current LOG_TAG.
171  */
172 #ifndef LOGE
173 #define LOGE(...) ((void)LOG(LOG_ERROR, LOG_TAG, __VA_ARGS__))
174 #endif
175
176 /**
177  * Simplified macro to send a conditional error log message using the current LOG_TAG.
178  */
179 #ifndef LOGE_IF
180 #define LOGE_IF(cond, ...) \
181     ( (CONDITION(cond)) \
182     ? ((void)LOG(LOG_ERROR, LOG_TAG, __VA_ARGS__)) \
183     : (void)0 )
184 #endif
185
186 // ---------------------------------------------------------------------
187
188 /**
189  * Simplified macro to send a verbose radio log message using the current LOG_TAG.
190  */
191 #ifndef RLOGV
192 #if LOG_NDEBUG
193 #define RLOGV(...)   ((void)0)
194 #else
195 #define RLOGV(...) ((void)RLOG(LOG_VERBOSE, LOG_TAG, __VA_ARGS__))
196 #endif
197 #endif
198         
199 /**
200  * Simplified macro to send a conditional verbose radio log message using the current LOG_TAG.
201  */     
202 #ifndef RLOGV_IF
203 #if LOG_NDEBUG
204 #define RLOGV_IF(cond, ...)   ((void)0)
205 #else
206 #define RLOGV_IF(cond, ...) \
207                 ( (CONDITION(cond)) \
208                 ? ((void)RLOG(LOG_VERBOSE, LOG_TAG, __VA_ARGS__)) \
209                 : (void)0 )
210 #endif
211 #endif
212         
213 /**
214  * Simplified macro to send a debug radio log message using the current LOG_TAG.
215  */
216 #ifndef RLOGD
217 #define RLOGD(...) ((void)RLOG(LOG_DEBUG, LOG_TAG, __VA_ARGS__))
218 #endif
219
220 /**
221  * Simplified macro to send a conditional debug radio log message using the current LOG_TAG.
222  */     
223 #ifndef RLOGD_IF
224 #define RLOGD_IF(cond, ...) \
225                 ( (CONDITION(cond)) \
226                 ? ((void)RLOG(LOG_DEBUG, LOG_TAG, __VA_ARGS__)) \
227                 : (void)0 )
228 #endif
229         
230 /**
231  * Simplified macro to send an info radio log message using the current LOG_TAG.
232  */
233 #ifndef RLOGI
234 #define RLOGI(...) ((void)RLOG(LOG_INFO, LOG_TAG, __VA_ARGS__))
235 #endif
236
237 /**
238  * Simplified macro to send a conditional info radio log message using the current LOG_TAG.
239  */
240 #ifndef RLOGI_IF
241 #define RLOGI_IF(cond, ...) \
242                 ( (CONDITION(cond)) \
243                 ? ((void)RLOG(LOG_INFO, LOG_TAG, __VA_ARGS__)) \
244                 : (void)0 )
245 #endif
246         
247 /**
248  * Simplified macro to send a warning radio log message using the current LOG_TAG.
249  */
250 #ifndef RLOGW
251 #define RLOGW(...) ((void)RLOG(LOG_WARN, LOG_TAG, __VA_ARGS__))
252 #endif
253
254 /**
255  * Simplified macro to send a conditional warning radio log message using the current LOG_TAG.
256  */
257 #ifndef RLOGW_IF
258 #define RLOGW_IF(cond, ...) \
259                 ( (CONDITION(cond)) \
260                 ? ((void)RLOG(LOG_WARN, LOG_TAG, __VA_ARGS__)) \
261                 : (void)0 )
262 #endif
263         
264 /**
265  * Simplified macro to send an error radio log message using the current LOG_TAG.
266  */
267 #ifndef RLOGE
268 #define RLOGE(...) ((void)RLOG(LOG_ERROR, LOG_TAG, __VA_ARGS__))
269 #endif
270
271 /**
272  * Simplified macro to send a conditional error radio log message using the current LOG_TAG.
273  */     
274 #ifndef RLOGE_IF
275 #define RLOGE_IF(cond, ...) \
276                 ( (CONDITION(cond)) \
277                 ? ((void)RLOG(LOG_ERROR, LOG_TAG, __VA_ARGS__)) \
278                 : (void)0 )
279 #endif
280
281 // ---------------------------------------------------------------------
282
283 /**
284  * Simplified macro to send a verbose system log message using the current LOG_TAG.
285  */
286 #ifndef SLOGV
287 #if LOG_NDEBUG
288 #define SLOGV(...)   ((void)0)
289 #else
290 #define SLOGV(...) ((void)SLOG(LOG_VERBOSE, LOG_TAG, __VA_ARGS__))
291 #endif
292 #endif
293
294 /**
295  * Simplified macro to send a conditional verbose system log message using the current LOG_TAG.
296  */
297 #ifndef SLOGV_IF
298 #if LOG_NDEBUG
299 #define SLOGV_IF(cond, ...)   ((void)0)
300 #else
301 #define SLOGV_IF(cond, ...) \
302                 ( (CONDITION(cond)) \
303                 ? ((void)SLOG(LOG_VERBOSE, LOG_TAG, __VA_ARGS__)) \
304                 : (void)0 )
305 #endif
306 #endif
307         
308 /**
309  * Simplified macro to send a debug system log message using the current LOG_TAG.
310  */
311 #ifndef SLOGD
312 #define SLOGD(...) ((void)SLOG(LOG_DEBUG, LOG_TAG, __VA_ARGS__))
313 #endif
314
315 /**
316  * Simplified macro to send a conditional debug system log message using the current LOG_TAG.
317  */
318 #ifndef SLOGD_IF
319 #define SLOGD_IF(cond, ...) \
320                 ( (CONDITION(cond)) \
321                 ? ((void)SLOG(LOG_DEBUG, LOG_TAG, __VA_ARGS__)) \
322                 : (void)0 )
323 #endif
324         
325 /**
326  * Simplified macro to send an info system log message using the current LOG_TAG.
327  */
328 #ifndef SLOGI
329 #define SLOGI(...) ((void)SLOG(LOG_INFO, LOG_TAG, __VA_ARGS__))
330 #endif
331
332 /**
333  * Simplified macro to send a conditional info system log message using the current LOG_TAG.
334  */
335 #ifndef SLOGI_IF
336 #define SLOGI_IF(cond, ...) \
337                 ( (CONDITION(cond)) \
338                 ? ((void)SLOG(LOG_INFO, LOG_TAG, __VA_ARGS__)) \
339                 : (void)0 )
340 #endif
341         
342 /**
343  * Simplified macro to send a warning system log message using the current LOG_TAG.
344  */
345 #ifndef SLOGW
346 #define SLOGW(...) ((void)SLOG(LOG_WARN, LOG_TAG, __VA_ARGS__))
347 #endif
348
349 /**
350  * Simplified macro to send a conditional warning system log message using the current LOG_TAG.
351  */
352 #ifndef SLOGW_IF
353 #define SLOGW_IF(cond, ...) \
354                 ( (CONDITION(cond)) \
355                 ? ((void)SLOG(LOG_WARN, LOG_TAG, __VA_ARGS__)) \
356                 : (void)0 )
357 #endif
358         
359 /**
360  * Simplified macro to send an error system log message using the current LOG_TAG.
361  */
362 #ifndef SLOGE
363 #define SLOGE(...) ((void)SLOG(LOG_ERROR, LOG_TAG, __VA_ARGS__))
364 #endif
365
366 /**
367  * Simplified macro to send a conditional error system log message using the current LOG_TAG.
368  */
369 #ifndef SLOGE_IF
370 #define SLOGE_IF(cond, ...) \
371                 ( (CONDITION(cond)) \
372                 ? ((void)SLOG(LOG_ERROR, LOG_TAG, __VA_ARGS__)) \
373                 : (void)0 )
374 #endif
375
376 // ---------------------------------------------------------------------
377
378 /**
379  * Simplified macro to send a verbose log message using the current LOG_TAG.
380  */
381 #ifndef ALOGV
382 #if LOG_NDEBUG
383 #define ALOGV(...)   ((void)0)
384 #else
385 #define ALOGV(...) ((void)ALOG(LOG_VERBOSE, LOG_TAG, __VA_ARGS__))
386
387 #endif
388 #endif
389
390 /**
391  * Simplified macro to send a conditional verbose log message using the current LOG_TAG.
392  */
393 #ifndef ALOGV_IF
394 #if LOG_NDEBUG
395 #define ALOGV_IF(cond, ...)   ((void)0)
396 #else
397 #define ALOGV_IF(cond, ...) \
398     ( (CONDITION(cond)) \
399     ? ((void)ALOG(LOG_VERBOSE, LOG_TAG, __VA_ARGS__)) \
400     : (void)0 )
401 #endif
402 #endif
403
404 /**
405  * Simplified macro to send a debug log message using the current LOG_TAG.
406  */
407 #ifndef ALOGD
408 #define ALOGD(...) ((void)ALOG(LOG_DEBUG, LOG_TAG, __VA_ARGS__))
409 #endif
410
411 /**
412  * Simplified macro to send a conditional debug log message using the current LOG_TAG.
413  */
414 #ifndef ALOGD_IF
415 #define ALOGD_IF(cond, ...) \
416     ( (CONDITION(cond)) \
417     ? ((void)ALOG(LOG_DEBUG, LOG_TAG, __VA_ARGS__)) \
418     : (void)0 )
419 #endif
420
421 /**
422  * Simplified macro to send an info log message using the current LOG_TAG.
423  */
424 #ifndef ALOGI
425 #define ALOGI(...) ((void)ALOG(LOG_INFO, LOG_TAG, __VA_ARGS__))
426 #endif
427
428 /**
429  * Simplified macro to send a conditional info log message using the current LOG_TAG.
430  */
431 #ifndef ALOGI_IF
432 #define ALOGI_IF(cond, ...) \
433     ( (CONDITION(cond)) \
434     ? ((void)ALOG(LOG_INFO, LOG_TAG, __VA_ARGS__)) \
435     : (void)0 )
436 #endif
437
438 /**
439  * Simplified macro to send a warning log message using the current LOG_TAG.
440  */
441 #ifndef ALOGW
442 #define ALOGW(...) ((void)ALOG(LOG_WARN, LOG_TAG, __VA_ARGS__))
443 #endif
444
445 /**
446  * Simplified macro to send a conditional warning log message using the current LOG_TAG.
447  */
448 #ifndef ALOGW_IF
449 #define ALOGW_IF(cond, ...) \
450     ( (CONDITION(cond)) \
451     ? ((void)ALOG(LOG_WARN, LOG_TAG, __VA_ARGS__)) \
452     : (void)0 )
453 #endif
454
455 /**
456  * Simplified macro to send an error log message using the current LOG_TAG.
457  */
458 #ifndef ALOGE
459 #define ALOGE(...) ((void)ALOG(LOG_ERROR, LOG_TAG, __VA_ARGS__))
460 #endif
461
462 /**
463  * Simplified macro to send a conditional error log message using the current LOG_TAG.
464  */
465 #ifndef ALOGE_IF
466 #define ALOGE_IF(cond, ...) \
467     ( (CONDITION(cond)) \
468     ? ((void)ALOG(LOG_ERROR, LOG_TAG, __VA_ARGS__)) \
469     : (void)0 )
470 #endif
471 // TODO : support fatal log
472
473 // ---------------------------------------------------------------------
474
475 /**
476  * Basic log message macro that allows you to specify a priority and a tag
477  *
478  * Example:
479  *  LOG(DLOG_WARN, NULL, "Failed with error %d", errno);
480  *
481  * The second argument may be NULL or "" to indicate the "global" tag.
482  * 
483  * Future work : we want to put filename and line number automatically only when debug build mode 
484  */
485 #ifndef LOG
486 #define LOG(priority, tag, ...) \
487         print_log(D##priority, tag, __VA_ARGS__)
488 #endif
489
490 /**
491  * Log macro that allows you to pass in a varargs ("args" is a va_list).
492  */
493 #ifndef LOG_VA
494 #define LOG_VA(priority, tag, fmt, args) \
495     vprint_log(D##priority, tag, fmt, args)
496 #endif
497
498 #ifndef ALOG
499 #define ALOG(priority, tag, ...) \
500         print_apps_log(D##priority, tag, __VA_ARGS__)
501 #endif
502 /**
503  * Log macro that allows you to pass in a varargs ("args" is a va_list).
504  */
505 #ifndef ALOG_VA
506 #define ALOG_VA(priority, tag, fmt, args) \
507     vprint_apps_log(D##priority, tag, fmt, args)
508 #endif
509
510 /**
511  * Basic radio log macro that allows you to specify a priority and a tag.
512  */
513 #ifndef RLOG
514 #define RLOG(priority, tag, ...) \
515         print_radio_log(D##priority, tag, __VA_ARGS__)
516 #endif
517
518 /**
519  * Radio log macro that allows you to pass in a varargs ("args" is a va_list).
520  */
521 #ifndef RLOG_VA
522 #define RLOG_VA(priority, tag, fmt, args) \
523     vprint_radio_log(D##priority, tag, fmt, args)
524 #endif
525
526 /**
527  * Basic system log macro that allows you to specify a priority and a tag.
528  */
529 #ifndef SLOG
530 #define SLOG(priority, tag, ...) \
531     print_system_log(D##priority, tag, __VA_ARGS__)
532 #endif
533
534 /**
535  * System log macro that allows you to pass in a varargs ("args" is a va_list).
536  */
537 #ifndef SLOG_VA
538 #define SLOG_VA(priority, tag, fmt, args) \
539     vprint_system_log(D##priority, tag, fmt, args)
540 #endif
541
542
543 /*
544  * ===========================================================================
545  *
546  * The stuff in the rest of this file should not be used directly.
547  */
548
549 #define print_apps_log(prio, tag, fmt...) \
550         __dlog_print(LOG_ID_APPS, prio, tag, fmt)
551
552 #define vprint_apps_log(prio, tag, fmt...) \
553         __dlog_vprint(LOG_ID_APPS, prio, tag, fmt)
554
555 #define print_log(prio, tag, fmt...) \
556         __dlog_print(LOG_ID_MAIN, prio, tag, fmt)
557
558 #define vprint_log(prio, tag, fmt...) \
559         __dlog_vprint(LOG_ID_MAIN, prio, tag, fmt)
560         
561 #define print_radio_log(prio, tag, fmt...)\
562         __dlog_print(LOG_ID_RADIO, prio, tag, fmt)
563
564 #define vprint_radio_log(prio, tag, fmt...) \
565         __dlog_vprint(LOG_ID_RADIO, prio, tag, fmt)
566
567 #define print_system_log(prio, tag, fmt...)\
568         __dlog_print(LOG_ID_SYSTEM, prio, tag, fmt)
569
570 #define vprint_system_log(prio, tag, fmt...) \
571         __dlog_vprint(LOG_ID_SYSTEM, prio, tag, fmt)
572
573 /**
574  * @brief               send log. must specify log_id ,priority, tag and format string.
575  * @pre         none
576  * @post                none
577  * @see         __dlog_vprint
578  * @remarks     you must not use this API directly. use macros instead.
579  * @param[in]   log_id  log device id
580  * @param[in]   prio    priority
581  * @param[in]   tag     tag
582  * @param[in]   fmt     format string 
583  * @return                      Operation result
584  * @retval              0>=     Success
585  * @retval              -1      Error
586  * @code
587 // you have to use LOG(), SLOG(), RLOG() family not to use __dlog_print() directly
588 // so below example is just for passing Documentation Verification !!!
589 #define LOG_TAG USR_TAG
590 #include<dlog.h>
591  __dlog_print(LOG_ID_MAIN, DLOG_INFO, USR_TAG, "you must not use this API directly");
592  * @endcode
593  */
594 int __dlog_print(log_id_t log_id, int prio, const char *tag, const char *fmt, ...);
595
596 /**
597  * @brief               send log with va_list. must specify log_id ,priority, tag and format string.
598  * @pre         none
599  * @post                none
600  * @see         __dlog_print 
601  * @remarks     you must not use this API directly. use macros instead. 
602  * @param[in]   log_id  log device id
603  * @param[in]   prio    priority
604  * @param[in]   tag     tag
605  * @param[in]   fmt     format string 
606  * @param[in]   ap      va_list 
607  * @return                      Operation result
608  * @retval              0>=     Success
609  * @retval              -1      Error
610  * @code
611  // you have to use LOG_VA(), SLOG_VA(), RLOG_VA() family not to use __dlog_print() directly
612  // so below example is just for passing Documentation Verification !!!
613 #define LOG_TAG USR_TAG
614 #include<dlog.h>
615   __dlog_vprint(LOG_ID_MAIN, DLOG_INFO, USR_TAG, "you must not use this API directly", ap);
616  * @endcode
617   */
618 int __dlog_vprint(log_id_t log_id, int prio, const char *tag, const char *fmt, va_list ap);
619
620 #ifdef __cplusplus
621 }
622 #endif /* __cplusplus */
623
624
625 /** @} */
626 /** @} */
627
628 #endif /* _DLOG_H_*/
629