change dlog control logic
[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  * @file        dlog.h
20  * @version     0.4
21  * @brief       This file is the header file of interface of dlog.
22  */
23 /**
24  * @addtogroup APPLICATION_FRAMEWORK
25  * @{
26  *
27  * @defgroup dlog dlog
28  * @addtogroup dlog
29  * @{
30
31  */
32 #ifndef _DLOG_H_
33 #define _DLOG_H_
34
35 #include<stdarg.h>
36 #include<string.h>
37
38 #ifdef __cplusplus
39 extern "C" {
40 #endif /* __cplusplus */
41
42 /*
43  * Normally we strip LOGV (VERBOSE messages) from release builds.
44  */
45 #ifndef LOG_NDEBUG
46 #ifdef NDEBUG
47 #define LOG_NDEBUG 1
48 #else
49 #define LOG_NDEBUG 0
50 #endif
51 #endif
52
53 /*
54  * This is the local tag used for the following simplified
55  * logging macros.  You can change this preprocessor definition
56  * before using the other macros to change the tag.
57  */
58 #ifndef LOG_TAG
59 #define LOG_TAG NULL
60 #endif
61
62 #ifndef __MODULE__
63 #define __MODULE__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__)
64 #endif
65
66 /*
67  * log priority values, in ascending priority order.
68  */
69 typedef enum {
70         DLOG_UNKNOWN = 0,
71         DLOG_DEFAULT,
72         DLOG_VERBOSE,
73         DLOG_DEBUG,
74         DLOG_INFO,
75         DLOG_WARN,
76         DLOG_ERROR,
77         DLOG_FATAL,
78         DLOG_SILENT,
79         DLOG_PRIO_MAX   /* Keep this always at the end. */
80 } log_priority;
81
82 typedef enum {
83     LOG_ID_MAIN = 0,
84         LOG_ID_RADIO,
85         LOG_ID_SYSTEM,
86         LOG_ID_APPS,
87         LOG_ID_MAX
88 } log_id_t;
89
90 #define CONDITION(cond)     (__builtin_expect((cond) != 0, 0))
91
92 #define _SECURE_LOG /* Temporary default added, This define code will be removed */
93
94 // Macro inner work---------------------------------------------------------------
95 #undef _SECURE_
96 #ifndef _SECURE_LOG
97 #define _SECURE_ (0)
98 #else
99 #define _SECURE_ (1)
100 #endif
101 #undef LOG_
102 #define LOG_(id, prio, tag, fmt, arg...) \
103         ( __dlog_print(id, prio, tag, "%s: %s(%d) > " fmt, __MODULE__, __func__, __LINE__, ##arg))
104 #undef SECURE_LOG_
105 #define SECURE_LOG_(id, prio, tag, fmt, arg...) \
106         (_SECURE_ ? ( __dlog_print(id, prio, tag, "%s: %s(%d) > [SECURE_LOG] " fmt, __MODULE__, __func__, __LINE__, ##arg)) : (0))
107 // ---------------------------------------------------------------------
108 /**
109  * For Secure Log.
110  * Normally we strip Secure log from release builds.
111  * Please use this macros.
112  */
113 /**
114  * For Application and etc.
115  * Simplified macro to send a main log message using the current LOG_TAG.
116  * Example:
117  *  SECURE_LOGD("app debug %d", num);
118  *  SECURE_LOGE("app error %d", num);
119  */
120 #define SECURE_LOGD(format, arg...) SECURE_LOG_(LOG_ID_MAIN, DLOG_DEBUG, LOG_TAG, format, ##arg)
121 #define SECURE_LOGI(format, arg...) SECURE_LOG_(LOG_ID_MAIN, DLOG_INFO, LOG_TAG, format, ##arg)
122 #define SECURE_LOGW(format, arg...) SECURE_LOG_(LOG_ID_MAIN, DLOG_WARN, LOG_TAG, format, ##arg)
123 #define SECURE_LOGE(format, arg...) SECURE_LOG_(LOG_ID_MAIN, DLOG_ERROR, LOG_TAG, format, ##arg)
124 /**
125  * For Framework and system etc.
126  * Simplified macro to send a system log message using the current LOG_TAG.
127  * Example:
128  *  SECURE_SLOGD("system debug %d", num);
129  *  SECURE_SLOGE("system error %d", num);
130  */
131 #define SECURE_SLOGD(format, arg...) SECURE_LOG_(LOG_ID_SYSTEM, DLOG_DEBUG, LOG_TAG, format, ##arg)
132 #define SECURE_SLOGI(format, arg...) SECURE_LOG_(LOG_ID_SYSTEM, DLOG_INFO, LOG_TAG, format, ##arg)
133 #define SECURE_SLOGW(format, arg...) SECURE_LOG_(LOG_ID_SYSTEM, DLOG_WARN, LOG_TAG, format, ##arg)
134 #define SECURE_SLOGE(format, arg...) SECURE_LOG_(LOG_ID_SYSTEM, DLOG_ERROR, LOG_TAG, format, ##arg)
135 /**
136  * For Modem and radio etc.
137  * Simplified macro to send a radio log message using the current LOG_TAG.
138  * Example:
139  *  SECURE_RLOGD("radio debug %d", num);
140  *  SECURE_RLOGE("radio error %d", num);
141  */
142 #define SECURE_RLOGD(format, arg...) SECURE_LOG_(LOG_ID_RADIO, DLOG_DEBUG, LOG_TAG, format, ##arg)
143 #define SECURE_RLOGI(format, arg...) SECURE_LOG_(LOG_ID_RADIO, DLOG_INFO, LOG_TAG, format, ##arg)
144 #define SECURE_RLOGW(format, arg...) SECURE_LOG_(LOG_ID_RADIO, DLOG_WARN, LOG_TAG, format, ##arg)
145 #define SECURE_RLOGE(format, arg...) SECURE_LOG_(LOG_ID_RADIO, DLOG_ERROR, LOG_TAG, format, ##arg)
146 /**
147  * For Tizen OSP Application macro.
148  */
149 #define SECURE_ALOGD(format, arg...) SECURE_LOG_(LOG_ID_APPS, DLOG_DEBUG, LOG_TAG, format, ##arg)
150 #define SECURE_ALOGI(format, arg...) SECURE_LOG_(LOG_ID_APPS, DLOG_INFO, LOG_TAG, format, ##arg)
151 #define SECURE_ALOGW(format, arg...) SECURE_LOG_(LOG_ID_APPS, DLOG_WARN, LOG_TAG, format, ##arg)
152 #define SECURE_ALOGE(format, arg...) SECURE_LOG_(LOG_ID_APPS, DLOG_ERROR, LOG_TAG, format, ##arg)
153 /**
154  * If you want use redefined macro.
155  * You can use this macro.
156  * This macro need priority and tag arguments.
157  */
158 #define SECURE_LOG(priority, tag, format, arg...) SECURE_LOG_(LOG_ID_MAIN, D##priority, tag, format, ##arg)
159 #define SECURE_SLOG(priority, tag, format, arg...) SECURE_LOG_(LOG_ID_SYSTEM, D##priority, tag, format, ##arg)
160 #define SECURE_RLOG(priority, tag, format, arg...) SECURE_LOG_(LOG_ID_RADIO, D##priority, tag, format, ##arg)
161 #define SECURE_ALOG(priority, tag, format, arg...) SECURE_LOG_(LOG_ID_APPS, D##priority, tag, format, ##arg)
162
163 #define SECLOG(format, arg...) do { } while (0)
164 /**
165  * For Application and etc.
166  * Simplified macro to send a main log message using the current LOG_TAG.
167  * Example:
168  *  LOGD("app debug %d", num);
169  *  LOGE("app error %d", num);
170  */
171 #define LOGD(format, arg...) LOG_(LOG_ID_MAIN, DLOG_DEBUG, LOG_TAG, format, ##arg)
172 #define LOGI(format, arg...) LOG_(LOG_ID_MAIN, DLOG_INFO, LOG_TAG, format, ##arg)
173 #define LOGW(format, arg...) LOG_(LOG_ID_MAIN, DLOG_WARN, LOG_TAG, format, ##arg)
174 #define LOGE(format, arg...) LOG_(LOG_ID_MAIN, DLOG_ERROR, LOG_TAG, format, ##arg)
175 /**
176  * For Framework and system etc.
177  * Simplified macro to send a system log message using the current LOG_TAG.
178  * Example:
179  *  SLOGD("system debug %d", num);
180  *  SLOGE("system error %d", num);
181  */
182 #define SLOGD(format, arg...) LOG_(LOG_ID_SYSTEM, DLOG_DEBUG, LOG_TAG, format, ##arg)
183 #define SLOGI(format, arg...) LOG_(LOG_ID_SYSTEM, DLOG_INFO, LOG_TAG, format, ##arg)
184 #define SLOGW(format, arg...) LOG_(LOG_ID_SYSTEM, DLOG_WARN, LOG_TAG, format, ##arg)
185 #define SLOGE(format, arg...) LOG_(LOG_ID_SYSTEM, DLOG_ERROR, LOG_TAG, format, ##arg)
186 /**
187  * For Modem and radio etc.
188  * Simplified macro to send a radio log message using the current LOG_TAG.
189  * Example:
190  *  RLOGD("radio debug %d", num);
191  *  RLOGE("radio error %d", num);
192  */
193 #define RLOGD(format, arg...) LOG_(LOG_ID_RADIO, DLOG_DEBUG, LOG_TAG, format, ##arg)
194 #define RLOGI(format, arg...) LOG_(LOG_ID_RADIO, DLOG_INFO, LOG_TAG, format, ##arg)
195 #define RLOGW(format, arg...) LOG_(LOG_ID_RADIO, DLOG_WARN, LOG_TAG, format, ##arg)
196 #define RLOGE(format, arg...) LOG_(LOG_ID_RADIO, DLOG_ERROR, LOG_TAG, format, ##arg)
197 /**
198  * For Tizen OSP Application macro.
199  */
200 #define ALOGD(format, arg...) LOG_(LOG_ID_APPS, DLOG_DEBUG, LOG_TAG, format, ##arg)
201 #define ALOGI(format, arg...) LOG_(LOG_ID_APPS, DLOG_INFO, LOG_TAG, format, ##arg)
202 #define ALOGW(format, arg...) LOG_(LOG_ID_APPS, DLOG_WARN, LOG_TAG, format, ##arg)
203 #define ALOGE(format, arg...) LOG_(LOG_ID_APPS, DLOG_ERROR, LOG_TAG, format, ##arg)
204
205 /**
206  * Conditional Macro.
207  * Don't use this macro. It's just compatibility.
208  */
209 #define LOGD_IF(cond, format, arg...) \
210     ((CONDITION(cond)) ? (LOGD(format, ##arg)) : (0))
211 #define LOGI_IF(cond, format, arg...) \
212     ((CONDITION(cond)) ? (LOGI(format, ##arg)) : (0))
213 #define LOGW_IF(cond, format, arg...) \
214     ((CONDITION(cond)) ? (LOGW(format, ##arg)) : (0))
215 #define LOGE_IF(cond, format, arg...) \
216     ((CONDITION(cond)) ? (LOGE(format, ##arg)) : (0))
217 #define SLOGD_IF(cond, format, arg...) \
218     ((CONDITION(cond)) ? (SLOGD(format, ##arg)) : (0))
219 #define SLOGI_IF(cond, format, arg...) \
220     ((CONDITION(cond)) ? (SLOGI(format, ##arg)) : (0))
221 #define SLOGW_IF(cond, format, arg...) \
222     ((CONDITION(cond)) ? (SLOGW(format, ##arg)) : (0))
223 #define SLOGE_IF(cond, format, arg...) \
224     ((CONDITION(cond)) ? (SLOGE(format, ##arg)) : (0))
225 #define RLOGD_IF(cond, format, arg...) \
226     ((CONDITION(cond)) ? (RLOGD(format, ##arg)) : (0))
227 #define RLOGI_IF(cond, format, arg...) \
228     ((CONDITION(cond)) ? (RLOGI(format, ##arg)) : (0))
229 #define RLOGW_IF(cond, format, arg...) \
230     ((CONDITION(cond)) ? (RLOGW(format, ##arg)) : (0))
231 #define RLOGE_IF(cond, format, arg...) \
232     ((CONDITION(cond)) ? (RLOGE(format, ##arg)) : (0))
233
234 /**
235  * Basic log message macro that allows you to specify a priority and a tag
236  * if you want to use this macro directly, you must add this messages for unity of messages.
237  * (LOG(prio, tag, "%s: %s(%d) > " format, __MODULE__, __func__, __LINE__, ##arg))
238  *
239  * Example:
240  *  #define MYMACRO(prio, tag, format, arg...) \
241  *          LOG(prio, tag, format, ##arg)
242  *
243  *  MYMACRO(LOG_DEBUG, MYTAG, "test mymacro %d", num);
244  *
245  */
246 #ifndef LOG
247 #define LOG(priority, tag, format, arg...) LOG_(LOG_ID_MAIN, D##priority, tag, format, ##arg)
248 #endif
249 #define SLOG(priority, tag, format, arg...) LOG_(LOG_ID_SYSTEM, D##priority, tag, format, ##arg)
250 #define RLOG(priority, tag, format, arg...) LOG_(LOG_ID_RADIO, D##priority, tag, format, ##arg)
251 #define ALOG(priority, tag, format, arg...) LOG_(LOG_ID_APPS, D##priority, tag, format, ##arg)
252
253
254 // ---------------------------------------------------------------------
255 // Don't use below macro no more!! It will be removed -- Verbose and Fatal priority macro will be removed --
256 #define COMPATIBILITY_ON
257
258 #ifdef COMPATIBILITY_ON
259 #define LOG_ON() _get_logging_on()
260 #if LOG_NDEBUG
261 #define LOGV(format, arg...) (0)
262 #else
263 #define LOGV(format, arg...) LOG_(LOG_ID_MAIN, DLOG_DEBUG, LOG_TAG, format, ##arg)
264 #endif
265 #define LOGF(format, arg...) LOG_(LOG_ID_MAIN, DLOG_ERROR, LOG_TAG, format, ##arg)
266 #if LOG_NDEBUG
267 #define SLOGV(format, arg...) (0)
268 #else
269 #define SLOGV(format, arg...) LOG_(LOG_ID_SYSTEM, DLOG_DEBUG, LOG_TAG, format, ##arg)
270 #endif
271 #define SLOGF(format, arg...) LOG_(LOG_ID_SYSTEM, DLOG_ERROR, LOG_TAG, format, ##arg)
272 #if LOG_NDEBUG
273 #define RLOGV(format, arg...) (0)
274 #else
275 #define RLOGV(format, arg...) LOG_(LOG_ID_RADIO, DLOG_DEBUG, LOG_TAG, format, ##arg)
276 #endif
277 #define RLOGF(format, arg...) LOG_(LOG_ID_RADIO, DLOG_ERROR, LOG_TAG, format, ##arg)
278 #if LOG_NDEBUG
279 #define ALOGV(format, arg...) (0)
280 #else
281 #define ALOGV(format, arg...) LOG_(LOG_ID_APPS, DLOG_DEBUG, LOG_TAG, format, ##arg)
282 #endif
283 #define ALOGF(format, arg...) LOG_(LOG_ID_APPS, DLOG_ERROR, LOG_TAG, format, ##arg)
284 #define LOGV_IF(cond, format, arg...) \
285     ((CONDITION(cond)) ? (LOGD(format, ##arg)) : (0))
286 #define LOGF_IF(cond, format, arg...) \
287     ((CONDITION(cond)) ? (LOGE(format, ##arg)) : (0))
288 #define SLOGV_IF(cond, format, arg...) \
289     ((CONDITION(cond)) ? (SLOGD(format, ##arg)) : (0))
290 #define SLOGF_IF(cond, format, arg...) \
291     ((CONDITION(cond)) ? (SLOGE(format, ##arg)) : (0))
292 #define RLOGV_IF(cond, format, arg...) \
293     ((CONDITION(cond)) ? (RLOGD(format, ##arg)) : (0))
294 #define RLOGF_IF(cond, format, arg...) \
295     ((CONDITION(cond)) ? (RLOGE(format, ##arg)) : (0))
296 #define LOG_VA(priority, tag, fmt, args) \
297     vprint_log(D##priority, tag, fmt, args)
298 #define ALOG_VA(priority, tag, fmt, args) \
299     vprint_apps_log(D##priority, tag, fmt, args)
300 #define RLOG_VA(priority, tag, fmt, args) \
301     vprint_radio_log(D##priority, tag, fmt, args)
302 #define SLOG_VA(priority, tag, fmt, args) \
303     vprint_system_log(D##priority, tag, fmt, args)
304 #define print_apps_log(prio, tag, fmt...) \
305         __dlog_print(LOG_ID_APPS, prio, tag, fmt)
306 #define vprint_apps_log(prio, tag, fmt...) \
307         __dlog_vprint(LOG_ID_APPS, prio, tag, fmt)
308 #define print_log(prio, tag, fmt...) \
309         __dlog_print(LOG_ID_MAIN, prio, tag, fmt)
310 #define vprint_log(prio, tag, fmt...) \
311         __dlog_vprint(LOG_ID_MAIN, prio, tag, fmt)
312 #define print_radio_log(prio, tag, fmt...)\
313         __dlog_print(LOG_ID_RADIO, prio, tag, fmt)
314 #define vprint_radio_log(prio, tag, fmt...) \
315         __dlog_vprint(LOG_ID_RADIO, prio, tag, fmt)
316 #define print_system_log(prio, tag, fmt...)\
317         __dlog_print(LOG_ID_SYSTEM, prio, tag, fmt)
318 #define vprint_system_log(prio, tag, fmt...) \
319         __dlog_vprint(LOG_ID_SYSTEM, prio, tag, fmt)
320 #endif
321 // Don't use above macro no more!! It will be removed -Verbose, Warning and Fatal priority macro.
322 // ---------------------------------------------------------------------
323 /*
324  * The stuff in the rest of this file should not be used directly.
325  */
326 /**
327  * @brief               send log. must specify log_id ,priority, tag and format string.
328  * @pre         none
329  * @post                none
330  * @see         __dlog_print
331  * @remarks     you must not use this API directly. use macros instead.
332  * @param[in]   log_id  log device id
333  * @param[in]   prio    priority
334  * @param[in]   tag     tag
335  * @param[in]   fmt     format string 
336  * @return                      Operation result
337  * @retval              0>=     Success
338  * @retval              -1      Error
339  * @code
340 // you have to use LOG(), SLOG(), RLOG() family not to use __dlog_print() directly
341 // so below example is just for passing Documentation Verification !!!
342 #define LOG_TAG USR_TAG
343 #include<dlog.h>
344  __dlog_print(LOG_ID_MAIN, DLOG_INFO, USR_TAG, "you must not use this API directly");
345  * @endcode
346  */
347 int __dlog_print(log_id_t log_id, int prio, const char *tag, const char *fmt, ...);
348
349 /**
350  * @brief               send log with va_list. must specify log_id ,priority, tag and format string.
351  * @pre         none
352  * @post                none
353  * @see         __dlog_print
354  * @remarks     you must not use this API directly. use macros instead.
355  * @param[in]   log_id  log device id
356  * @param[in]   prio    priority
357  * @param[in]   tag     tag
358  * @param[in]   fmt     format string
359  * @param[in]   ap      va_list
360  * @return                      Operation result
361  * @retval              0>=     Success
362  * @retval              -1      Error
363  * @code
364  // you have to use LOG_VA(), SLOG_VA(), RLOG_VA() family not to use __dlog_print() directly
365  // so below example is just for passing Documentation Verification !!!
366 #define LOG_TAG USR_TAG
367 #include<dlog.h>
368   __dlog_vprint(LOG_ID_MAIN, DLOG_INFO, USR_TAG, "you must not use this API directly", ap);
369  * @endcode
370   */
371 int __dlog_vprint(log_id_t log_id, int prio, const char *tag, const char *fmt, va_list ap);
372 int _get_logging_on(void);
373 #ifdef __cplusplus
374 }
375 #endif /* __cplusplus */
376 /** @} */
377 /** @} */
378 #endif /* _DLOG_H_*/