acc465630e74fa9744489a5e3fc9acff91bd30d3
[framework/system/dlog.git] / include / dlog.h
1 /*
2  * DLOG
3  * Copyright (c) 2005-2008, The Android Open Source Project
4  * Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
5  *
6  * Licensed under the Apache License, Version 2.0 (the License);
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *     http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18
19 /**
20  * @file        dlog.h
21  * @version     0.4
22  * @brief       This file is the header file of interface of dlog.
23  */
24 /**
25  * @addtogroup CAPI_BASE_DLOG_MODULE
26  * @{
27  *
28  */
29 #ifndef _DLOG_H_
30 #define _DLOG_H_
31
32 #include <stdarg.h>
33 #include <string.h>
34
35 #ifdef __cplusplus
36 extern "C" {
37 #endif /* __cplusplus */
38
39 /*
40  * This is the local tag used for the following simplified
41  * logging macros.  You can change this preprocessor definition
42  * before using the other macros to change the tag.
43  */
44 #ifndef LOG_TAG
45 #define LOG_TAG NULL
46 #endif
47
48 #ifndef __MODULE__
49 #define __MODULE__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__)
50 #endif
51
52 #ifdef TIZEN_ENGINEER_MODE
53 #ifndef TIZEN_DEBUG_ENABLE
54 #define TIZEN_DEBUG_ENABLE
55 #endif
56 #endif
57
58 /*
59  * log priority values, in ascending priority order.
60  */
61 typedef enum {
62         DLOG_UNKNOWN = 0,
63         DLOG_DEFAULT,
64         DLOG_VERBOSE,
65         DLOG_DEBUG,
66         DLOG_INFO,
67         DLOG_WARN,
68         DLOG_ERROR,
69         DLOG_FATAL,
70         DLOG_SILENT,
71         DLOG_PRIO_MAX   /* Keep this always at the end. */
72 } log_priority;
73
74 typedef enum {
75     LOG_ID_MAIN = 0,
76         LOG_ID_RADIO,
77         LOG_ID_SYSTEM,
78         LOG_ID_APPS,
79         LOG_ID_MAX
80 } log_id_t;
81
82 #define CONDITION(cond)     (__builtin_expect((cond) != 0, 0))
83 #define NOP(fmt, arg...) ({ do { } while (0); })
84
85 // Macro inner work---------------------------------------------------------------
86 #undef LOG_
87 #ifdef TIZEN_DEBUG_ENABLE
88 #define LOG_(id, prio, tag, fmt, arg...) \
89         ({ do { \
90                 __dlog_print(id, prio, tag, "%s: %s(%d) > " fmt, __MODULE__, __func__, __LINE__, ##arg); \
91         } while (0); })
92 #else
93 #define LOG_(id, prio, tag, fmt, arg...) \
94         ({ do { \
95                 if ((int)prio != DLOG_DEBUG) { \
96                         __dlog_print(id, prio, tag, "%s: %s(%d) > " fmt, __MODULE__, __func__, __LINE__, ##arg); \
97                 } \
98         } while (0); })
99 #endif
100
101 #undef SECURE_LOG_
102 #ifdef TIZEN_DEBUG_ENABLE
103 #define SECURE_LOG_(id, prio, tag, fmt, arg...) \
104         ({ do { \
105                 __dlog_print(id, prio, tag, "%s: %s(%d) > [SECURE_LOG] " fmt, __MODULE__, __func__, __LINE__, ##arg); \
106         } while (0); })
107 #else
108 #define SECURE_LOG_(id, prio, tag, fmt, arg...) NOP(fmt, ##arg)
109 #endif
110 // ---------------------------------------------------------------------
111 /**
112  * For Secure Log.
113  * Normally we strip Secure log from release builds.
114  * Please use this macros.
115  */
116 /**
117  * For Application and etc.
118  * Simplified macro to send a main log message using the current LOG_TAG.
119  * Example:
120  *  SECURE_LOGD("app debug %d", num);
121  *  SECURE_LOGE("app error %d", num);
122  */
123 #define SECURE_LOGD(format, arg...) SECURE_LOG_(LOG_ID_MAIN, DLOG_DEBUG, LOG_TAG, format, ##arg)
124 #define SECURE_LOGI(format, arg...) SECURE_LOG_(LOG_ID_MAIN, DLOG_INFO, LOG_TAG, format, ##arg)
125 #define SECURE_LOGW(format, arg...) SECURE_LOG_(LOG_ID_MAIN, DLOG_WARN, LOG_TAG, format, ##arg)
126 #define SECURE_LOGE(format, arg...) SECURE_LOG_(LOG_ID_MAIN, DLOG_ERROR, LOG_TAG, format, ##arg)
127 #define SECURE_LOGF(format, arg...) SECURE_LOG_(LOG_ID_MAIN, DLOG_FATAL, LOG_TAG, format, ##arg)
128 /**
129  * For Framework and system etc.
130  * Simplified macro to send a system log message using the current LOG_TAG.
131  * Example:
132  *  SECURE_SLOGD("system debug %d", num);
133  *  SECURE_SLOGE("system error %d", num);
134  */
135 #define SECURE_SLOGD(format, arg...) SECURE_LOG_(LOG_ID_SYSTEM, DLOG_DEBUG, LOG_TAG, format, ##arg)
136 #define SECURE_SLOGI(format, arg...) SECURE_LOG_(LOG_ID_SYSTEM, DLOG_INFO, LOG_TAG, format, ##arg)
137 #define SECURE_SLOGW(format, arg...) SECURE_LOG_(LOG_ID_SYSTEM, DLOG_WARN, LOG_TAG, format, ##arg)
138 #define SECURE_SLOGE(format, arg...) SECURE_LOG_(LOG_ID_SYSTEM, DLOG_ERROR, LOG_TAG, format, ##arg)
139 #define SECURE_SLOGF(format, arg...) SECURE_LOG_(LOG_ID_SYSTEM, DLOG_FATAL, LOG_TAG, format, ##arg)
140 /**
141  * For Modem and radio etc.
142  * Simplified macro to send a radio log message using the current LOG_TAG.
143  * Example:
144  *  SECURE_RLOGD("radio debug %d", num);
145  *  SECURE_RLOGE("radio error %d", num);
146  */
147 #define SECURE_RLOGD(format, arg...) SECURE_LOG_(LOG_ID_RADIO, DLOG_DEBUG, LOG_TAG, format, ##arg)
148 #define SECURE_RLOGI(format, arg...) SECURE_LOG_(LOG_ID_RADIO, DLOG_INFO, LOG_TAG, format, ##arg)
149 #define SECURE_RLOGW(format, arg...) SECURE_LOG_(LOG_ID_RADIO, DLOG_WARN, LOG_TAG, format, ##arg)
150 #define SECURE_RLOGE(format, arg...) SECURE_LOG_(LOG_ID_RADIO, DLOG_ERROR, LOG_TAG, format, ##arg)
151 #define SECURE_RLOGF(format, arg...) SECURE_LOG_(LOG_ID_RADIO, DLOG_FATAL, LOG_TAG, format, ##arg)
152 /**
153  * For Tizen OSP Application macro.
154  */
155 #define SECURE_ALOGD(format, arg...) SECURE_LOG_(LOG_ID_APPS, DLOG_DEBUG, LOG_TAG, format, ##arg)
156 #define SECURE_ALOGI(format, arg...) SECURE_LOG_(LOG_ID_APPS, DLOG_INFO, LOG_TAG, format, ##arg)
157 #define SECURE_ALOGW(format, arg...) SECURE_LOG_(LOG_ID_APPS, DLOG_WARN, LOG_TAG, format, ##arg)
158 #define SECURE_ALOGE(format, arg...) SECURE_LOG_(LOG_ID_APPS, DLOG_ERROR, LOG_TAG, format, ##arg)
159 #define SECURE_ALOGF(format, arg...) SECURE_LOG_(LOG_ID_APPS, DLOG_FATAL, LOG_TAG, format, ##arg)
160 /**
161  * If you want use redefined macro.
162  * You can use this macro.
163  * This macro need priority and tag arguments.
164  */
165 #define SECURE_LOG(priority, tag, format, arg...) SECURE_LOG_(LOG_ID_MAIN, D##priority, tag, format, ##arg)
166 #define SECURE_SLOG(priority, tag, format, arg...) SECURE_LOG_(LOG_ID_SYSTEM, D##priority, tag, format, ##arg)
167 #define SECURE_RLOG(priority, tag, format, arg...) SECURE_LOG_(LOG_ID_RADIO, D##priority, tag, format, ##arg)
168 #define SECURE_ALOG(priority, tag, format, arg...) SECURE_LOG_(LOG_ID_APPS, D##priority, tag, format, ##arg)
169
170 /**
171  * For Application and etc.
172  * Simplified macro to send a main log message using the current LOG_TAG.
173  * Example:
174  *  LOGD("app debug %d", num);
175  *  LOGE("app error %d", num);
176  */
177 #ifdef TIZEN_DEBUG_ENABLE
178 #define LOGD(format, arg...) LOG_(LOG_ID_MAIN, DLOG_DEBUG, LOG_TAG, format, ##arg)
179 #else
180 #define LOGD(format, arg...) NOP(format, ##arg)
181 #endif
182 #define LOGI(format, arg...) LOG_(LOG_ID_MAIN, DLOG_INFO, LOG_TAG, format, ##arg)
183 #define LOGW(format, arg...) LOG_(LOG_ID_MAIN, DLOG_WARN, LOG_TAG, format, ##arg)
184 #define LOGE(format, arg...) LOG_(LOG_ID_MAIN, DLOG_ERROR, LOG_TAG, format, ##arg)
185 #define LOGF(format, arg...) LOG_(LOG_ID_MAIN, DLOG_FATAL, LOG_TAG, format, ##arg)
186 /**
187  * For Framework and system etc.
188  * Simplified macro to send a system log message using the current LOG_TAG.
189  * Example:
190  *  SLOGD("system debug %d", num);
191  *  SLOGE("system error %d", num);
192  */
193 #ifdef TIZEN_DEBUG_ENABLE
194 #define SLOGD(format, arg...) LOG_(LOG_ID_SYSTEM, DLOG_DEBUG, LOG_TAG, format, ##arg)
195 #else
196 #define SLOGD(format, arg...) NOP(format, ##arg)
197 #endif
198 #define SLOGI(format, arg...) LOG_(LOG_ID_SYSTEM, DLOG_INFO, LOG_TAG, format, ##arg)
199 #define SLOGW(format, arg...) LOG_(LOG_ID_SYSTEM, DLOG_WARN, LOG_TAG, format, ##arg)
200 #define SLOGE(format, arg...) LOG_(LOG_ID_SYSTEM, DLOG_ERROR, LOG_TAG, format, ##arg)
201 #define SLOGF(format, arg...) LOG_(LOG_ID_SYSTEM, DLOG_FATAL, LOG_TAG, format, ##arg)
202 /**
203  * For Modem and radio etc.
204  * Simplified macro to send a radio log message using the current LOG_TAG.
205  * Example:
206  *  RLOGD("radio debug %d", num);
207  *  RLOGE("radio error %d", num);
208  */
209 #ifdef TIZEN_DEBUG_ENABLE
210 #define RLOGD(format, arg...) LOG_(LOG_ID_RADIO, DLOG_DEBUG, LOG_TAG, format, ##arg)
211 #else
212 #define RLOGD(format, arg...) NOP(format, ##arg)
213 #endif
214 #define RLOGI(format, arg...) LOG_(LOG_ID_RADIO, DLOG_INFO, LOG_TAG, format, ##arg)
215 #define RLOGW(format, arg...) LOG_(LOG_ID_RADIO, DLOG_WARN, LOG_TAG, format, ##arg)
216 #define RLOGE(format, arg...) LOG_(LOG_ID_RADIO, DLOG_ERROR, LOG_TAG, format, ##arg)
217 #define RLOGF(format, arg...) LOG_(LOG_ID_RADIO, DLOG_FATAL, LOG_TAG, format, ##arg)
218 /**
219  * For Tizen OSP Application macro.
220  */
221 #ifdef TIZEN_DEBUG_ENABLE
222 #define ALOGD(format, arg...) LOG_(LOG_ID_APPS, DLOG_DEBUG, LOG_TAG, format, ##arg)
223 #else
224 #define ALOGD(format, arg...) NOP(format, ##arg)
225 #endif
226 #define ALOGI(format, arg...) LOG_(LOG_ID_APPS, DLOG_INFO, LOG_TAG, format, ##arg)
227 #define ALOGW(format, arg...) LOG_(LOG_ID_APPS, DLOG_WARN, LOG_TAG, format, ##arg)
228 #define ALOGE(format, arg...) LOG_(LOG_ID_APPS, DLOG_ERROR, LOG_TAG, format, ##arg)
229 #define ALOGF(format, arg...) LOG_(LOG_ID_APPS, DLOG_FATAL, LOG_TAG, format, ##arg)
230
231 /**
232  * Basic log message macro that allows you to specify a priority and a tag
233  * if you want to use this macro directly, you must add this messages for unity of messages.
234  * (LOG(prio, tag, "%s: %s(%d) > " format, __MODULE__, __func__, __LINE__, ##arg))
235  *
236  * Example:
237  *  #define MYMACRO(prio, tag, format, arg...) \
238  *          LOG(prio, tag, format, ##arg)
239  *
240  *  MYMACRO(LOG_DEBUG, MYTAG, "test mymacro %d", num);
241  *
242  */
243 #ifndef LOG
244 #define LOG(priority, tag, format, arg...) LOG_(LOG_ID_MAIN, D##priority, tag, format, ##arg)
245 #endif
246 #define SLOG(priority, tag, format, arg...) LOG_(LOG_ID_SYSTEM, D##priority, tag, format, ##arg)
247 #define RLOG(priority, tag, format, arg...) LOG_(LOG_ID_RADIO, D##priority, tag, format, ##arg)
248 #define ALOG(priority, tag, format, arg...) LOG_(LOG_ID_APPS, D##priority, tag, format, ##arg)
249
250 #define LOG_VA(priority, tag, fmt, args) \
251         vprint_log(D##priority, tag, fmt, args)
252 #define ALOG_VA(priority, tag, fmt, args) \
253         vprint_apps_log(D##priority, tag, fmt, args)
254 #define RLOG_VA(priority, tag, fmt, args) \
255         vprint_radio_log(D##priority, tag, fmt, args)
256 #define SLOG_VA(priority, tag, fmt, args) \
257         vprint_system_log(D##priority, tag, fmt, args)
258 #define print_apps_log(prio, tag, fmt...) \
259         __dlog_print(LOG_ID_APPS, prio, tag, fmt)
260 #define vprint_apps_log(prio, tag, fmt...) \
261         __dlog_vprint(LOG_ID_APPS, prio, tag, fmt)
262 #define print_log(prio, tag, fmt...) \
263         __dlog_print(LOG_ID_MAIN, prio, tag, fmt)
264 #define vprint_log(prio, tag, fmt...) \
265         __dlog_vprint(LOG_ID_MAIN, prio, tag, fmt)
266 #define print_radio_log(prio, tag, fmt...)\
267         __dlog_print(LOG_ID_RADIO, prio, tag, fmt)
268 #define vprint_radio_log(prio, tag, fmt...) \
269         __dlog_vprint(LOG_ID_RADIO, prio, tag, fmt)
270 #define print_system_log(prio, tag, fmt...)\
271         __dlog_print(LOG_ID_SYSTEM, prio, tag, fmt)
272 #define vprint_system_log(prio, tag, fmt...) \
273         __dlog_vprint(LOG_ID_SYSTEM, prio, tag, fmt)
274
275 // ---------------------------------------------------------------------
276 // Don't use below macro no more!! It will be removed -- Verbose and Fatal priority macro will be removed --
277 #define COMPATIBILITY_ON
278 #ifdef COMPATIBILITY_ON
279 /**
280  * Conditional Macro.
281  * Don't use this macro. It's just compatibility.
282  * It will be deprecated.
283  */
284 #define LOGD_IF(cond, format, arg...) \
285         ({ do { \
286                 if (CONDITION(cond)) { \
287                         LOGD(format, ##arg); \
288                 } \
289         } while (0); })
290 #define LOGI_IF(cond, format, arg...) \
291         ({ do { \
292                 if (CONDITION(cond)) { \
293                         LOGI(format, ##arg); \
294                 } \
295         } while (0); })
296 #define LOGW_IF(cond, format, arg...) \
297         ({ do { \
298                 if (CONDITION(cond)) { \
299                         LOGW(format, ##arg); \
300                 } \
301         } while (0); })
302 #define LOGE_IF(cond, format, arg...) \
303         ({ do { \
304                 if (CONDITION(cond)) { \
305                         LOGE(format, ##arg); \
306                 } \
307         } while (0); })
308 #define LOGF_IF(cond, format, arg...) \
309         ({ do { \
310                 if (CONDITION(cond)) { \
311                         LOGF(format, ##arg); \
312                 } \
313         } while (0); })
314 #define SLOGD_IF(cond, format, arg...) \
315         ({ do { \
316                 if (CONDITION(cond)) { \
317                         SLOGD(format, ##arg); \
318                 } \
319         } while (0); })
320 #define SLOGI_IF(cond, format, arg...) \
321         ({ do { \
322                 if (CONDITION(cond)) { \
323                         SLOGI(format, ##arg); \
324                 } \
325         } while (0); })
326 #define SLOGW_IF(cond, format, arg...) \
327         ({ do { \
328                 if (CONDITION(cond)) { \
329                         SLOGW(format, ##arg); \
330                 } \
331         } while (0); })
332 #define SLOGE_IF(cond, format, arg...) \
333         ({ do { \
334                 if (CONDITION(cond)) { \
335                         SLOGE(format, ##arg); \
336                 } \
337         } while (0); })
338 #define SLOGF_IF(cond, format, arg...) \
339         ({ do { \
340                 if (CONDITION(cond)) { \
341                         SLOGF(format, ##arg); \
342                 } \
343         } while (0); })
344 #define RLOGD_IF(cond, format, arg...) \
345         ({ do { \
346                 if (CONDITION(cond)) { \
347                         RLOGD(format, ##arg); \
348                 } \
349         } while (0); })
350 #define RLOGI_IF(cond, format, arg...) \
351         ({ do { \
352                 if (CONDITION(cond)) { \
353                         RLOGI(format, ##arg); \
354                 } \
355         } while (0); })
356 #define RLOGW_IF(cond, format, arg...) \
357         ({ do { \
358                 if (CONDITION(cond)) { \
359                         RLOGW(format, ##arg); \
360                 } \
361         } while (0); })
362 #define RLOGE_IF(cond, format, arg...) \
363         ({ do { \
364                 if (CONDITION(cond)) { \
365                         RLOGE(format, ##arg); \
366                 } \
367         } while (0); })
368 #define RLOGF_IF(cond, format, arg...) \
369         ({ do { \
370                 if (CONDITION(cond)) { \
371                         RLOGF(format, ##arg); \
372                 } \
373         } while (0); })
374 #define LOG_ON() ({ do { } while (0); })
375 #define LOGV(format, arg...) NOP(format, ##arg)
376 #define SLOGV(format, arg...) NOP(format, ##arg)
377 #define RLOGV(format, arg...) NOP(format, ##arg)
378 #define ALOGV(format, arg...) NOP(format, ##arg)
379 #define LOGV_IF(cond, format, arg...) NOP(format, ##arg)
380 #define SLOGV_IF(cond, format, arg...) NOP(format, ##arg)
381 #define RLOGV_IF(cond, format, arg...) NOP(format, ##arg)
382 #define SECLOG(...) ({ do { } while (0); })
383 #endif
384 // Don't use above macro no more!! It will be removed -Verbose, Warning and Fatal priority macro.
385 // ---------------------------------------------------------------------
386 /*
387  * The stuff in the rest of this file should not be used directly.
388  */
389 /**
390  * @brief               send log. must specify log_id ,priority, tag and format string.
391  * @pre         none
392  * @post                none
393  * @see         __dlog_print
394  * @remarks     you must not use this API directly. use macros instead.
395  * @param[in]   log_id  log device id
396  * @param[in]   prio    priority
397  * @param[in]   tag     tag
398  * @param[in]   fmt     format string
399  * @return                      Operation result
400  * @retval              0>=     Success
401  * @retval              -1      Error
402  * @code
403 // you have to use LOG(), SLOG(), RLOG() family not to use __dlog_print() directly
404 // so below example is just for passing Documentation Verification !!!
405 #define LOG_TAG USR_TAG
406 #include<dlog.h>
407  __dlog_print(LOG_ID_MAIN, DLOG_INFO, USR_TAG, "you must not use this API directly");
408  * @endcode
409  */
410 int __dlog_print(log_id_t log_id, int prio, const char *tag, const char *fmt, ...);
411
412 /**
413  * @brief               send log with va_list. must specify log_id ,priority, tag and format string.
414  * @pre         none
415  * @post                none
416  * @see         __dlog_print
417  * @remarks     you must not use this API directly. use macros instead.
418  * @param[in]   log_id  log device id
419  * @param[in]   prio    priority
420  * @param[in]   tag     tag
421  * @param[in]   fmt     format string
422  * @param[in]   ap      va_list
423  * @return                      Operation result
424  * @retval              0>=     Success
425  * @retval              -1      Error
426  * @code
427  // you have to use LOG_VA(), SLOG_VA(), RLOG_VA() family not to use __dlog_print() directly
428  // so below example is just for passing Documentation Verification !!!
429 #define LOG_TAG USR_TAG
430 #include<dlog.h>
431   __dlog_vprint(LOG_ID_MAIN, DLOG_INFO, USR_TAG, "you must not use this API directly", ap);
432  * @endcode
433   */
434 int __dlog_vprint(log_id_t log_id, int prio, const char *tag, const char *fmt, va_list ap);
435 #ifdef __cplusplus
436 }
437 #endif /* __cplusplus */
438 /** @} */
439 #endif /* _DLOG_H_*/