3 * Copyright (c) 2005-2008, The Android Open Source Project
4 * Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
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
10 * http://www.apache.org/licenses/LICENSE-2.0
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.
22 * @brief This file is the header file of interface of dlog.
27 #include <tizen_error.h>
33 #endif /* __cplusplus */
36 * This is the local tag used for the following simplified
37 * logging macros. You can change this preprocessor definition
38 * before using the other macros to change the tag.
45 #define __MODULE__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__)
48 #ifdef TIZEN_ENGINEER_MODE
49 #ifndef TIZEN_DEBUG_ENABLE
50 #define TIZEN_DEBUG_ENABLE
55 * @addtogroup CAPI_SYSTEM_DLOG
60 * @brief Enumeration for Dlog Error.
61 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
64 DLOG_ERROR_NONE = TIZEN_ERROR_NONE, /**< Successful */
65 DLOG_ERROR_INVALID_PARAMETER = TIZEN_ERROR_INVALID_PARAMETER, /**< Invalid parameter */
66 DLOG_ERROR_NOT_PERMITTED = TIZEN_ERROR_NOT_PERMITTED, /**< Operation not permitted */
73 * @addtogroup CAPI_SYSTEM_DLOG
78 * @brief log priority values, in ascending priority order.
79 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
82 DLOG_UNKNOWN = 0, /**< Keep this always at the start */
83 DLOG_DEFAULT, /**< Default */
84 DLOG_VERBOSE, /**< Verbose */
85 DLOG_DEBUG, /**< Debug */
86 DLOG_INFO, /**< Info */
87 DLOG_WARN, /**< Warning */
88 DLOG_ERROR, /**< Error */
89 DLOG_FATAL, /**< Fatal */
90 DLOG_SILENT, /**< Silent */
91 DLOG_PRIO_MAX /**< Keep this always at the end. */
100 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
110 static inline int __dlog_no_print(const char *fmt __attribute__((unused)), ...) { return 0; }
112 #define CONDITION(cond) (__builtin_expect((cond) != 0, 0))
113 #define NOP(...) ({ do { __dlog_no_print(__VA_ARGS__); } while (0); })
115 // Macro inner work---------------------------------------------------------------
117 #ifdef TIZEN_DEBUG_ENABLE
118 #define LOG_(id, prio, tag, fmt, arg...) \
120 __dlog_print(id, prio, tag, "%s: %s(%d) > " fmt, __MODULE__, __func__, __LINE__, ##arg); \
123 #define LOG_(id, prio, tag, fmt, arg...) \
125 if ((int)prio != DLOG_DEBUG) { \
126 __dlog_print(id, prio, tag, "%s: %s(%d) > " fmt, __MODULE__, __func__, __LINE__, ##arg); \
132 #ifdef TIZEN_DEBUG_ENABLE
133 #define SECURE_LOG_(id, prio, tag, fmt, arg...) \
135 __dlog_print(id, prio, tag, "%s: %s(%d) > [SECURE_LOG] " fmt, __MODULE__, __func__, __LINE__, ##arg); \
138 #define SECURE_LOG_(id, prio, tag, fmt, arg...) NOP(fmt, ##arg)
140 // ---------------------------------------------------------------------
143 * @brief For Secure Log.
144 * @remarks Normally we strip Secure log from release builds.
145 * Please use this macros.
149 * @brief For Application and etc.
150 * @details Simplified macro to send a main log message using the current LOG_TAG.
152 * SECURE_LOGD("app debug %d", num);
153 * SECURE_LOGE("app error %d", num);
155 #define SECURE_LOGD(format, arg...) SECURE_LOG_(LOG_ID_MAIN, DLOG_DEBUG, LOG_TAG, format, ##arg)
156 #define SECURE_LOGI(format, arg...) SECURE_LOG_(LOG_ID_MAIN, DLOG_INFO, LOG_TAG, format, ##arg)
157 #define SECURE_LOGW(format, arg...) SECURE_LOG_(LOG_ID_MAIN, DLOG_WARN, LOG_TAG, format, ##arg)
158 #define SECURE_LOGE(format, arg...) SECURE_LOG_(LOG_ID_MAIN, DLOG_ERROR, LOG_TAG, format, ##arg)
159 #define SECURE_LOGF(format, arg...) SECURE_LOG_(LOG_ID_MAIN, DLOG_FATAL, LOG_TAG, format, ##arg)
162 * @brief For Framework and system etc.
163 * @details Simplified macro to send a system log message using the current LOG_TAG.
165 * SECURE_SLOGD("system debug %d", num);
166 * SECURE_SLOGE("system error %d", num);
168 #define SECURE_SLOGD(format, arg...) SECURE_LOG_(LOG_ID_SYSTEM, DLOG_DEBUG, LOG_TAG, format, ##arg)
169 #define SECURE_SLOGI(format, arg...) SECURE_LOG_(LOG_ID_SYSTEM, DLOG_INFO, LOG_TAG, format, ##arg)
170 #define SECURE_SLOGW(format, arg...) SECURE_LOG_(LOG_ID_SYSTEM, DLOG_WARN, LOG_TAG, format, ##arg)
171 #define SECURE_SLOGE(format, arg...) SECURE_LOG_(LOG_ID_SYSTEM, DLOG_ERROR, LOG_TAG, format, ##arg)
172 #define SECURE_SLOGF(format, arg...) SECURE_LOG_(LOG_ID_SYSTEM, DLOG_FATAL, LOG_TAG, format, ##arg)
175 * @brief For Modem and radio etc.
176 * @details Simplified macro to send a radio log message using the current LOG_TAG.
178 * SECURE_RLOGD("radio debug %d", num);
179 * SECURE_RLOGE("radio error %d", num);
181 #define SECURE_RLOGD(format, arg...) SECURE_LOG_(LOG_ID_RADIO, DLOG_DEBUG, LOG_TAG, format, ##arg)
182 #define SECURE_RLOGI(format, arg...) SECURE_LOG_(LOG_ID_RADIO, DLOG_INFO, LOG_TAG, format, ##arg)
183 #define SECURE_RLOGW(format, arg...) SECURE_LOG_(LOG_ID_RADIO, DLOG_WARN, LOG_TAG, format, ##arg)
184 #define SECURE_RLOGE(format, arg...) SECURE_LOG_(LOG_ID_RADIO, DLOG_ERROR, LOG_TAG, format, ##arg)
185 #define SECURE_RLOGF(format, arg...) SECURE_LOG_(LOG_ID_RADIO, DLOG_FATAL, LOG_TAG, format, ##arg)
188 * @brief For Tizen OSP Application macro.
190 #define SECURE_ALOGD(format, arg...) SECURE_LOG_(LOG_ID_APPS, DLOG_DEBUG, LOG_TAG, format, ##arg)
191 #define SECURE_ALOGI(format, arg...) SECURE_LOG_(LOG_ID_APPS, DLOG_INFO, LOG_TAG, format, ##arg)
192 #define SECURE_ALOGW(format, arg...) SECURE_LOG_(LOG_ID_APPS, DLOG_WARN, LOG_TAG, format, ##arg)
193 #define SECURE_ALOGE(format, arg...) SECURE_LOG_(LOG_ID_APPS, DLOG_ERROR, LOG_TAG, format, ##arg)
194 #define SECURE_ALOGF(format, arg...) SECURE_LOG_(LOG_ID_APPS, DLOG_FATAL, LOG_TAG, format, ##arg)
197 * @details If you want use redefined macro.
198 * You can use this macro.
199 * This macro need priority and tag arguments.
201 #define SECURE_LOG(priority, tag, format, arg...) SECURE_LOG_(LOG_ID_MAIN, D##priority, tag, format, ##arg)
202 #define SECURE_SLOG(priority, tag, format, arg...) SECURE_LOG_(LOG_ID_SYSTEM, D##priority, tag, format, ##arg)
203 #define SECURE_RLOG(priority, tag, format, arg...) SECURE_LOG_(LOG_ID_RADIO, D##priority, tag, format, ##arg)
204 #define SECURE_ALOG(priority, tag, format, arg...) SECURE_LOG_(LOG_ID_APPS, D##priority, tag, format, ##arg)
208 * @brief For Application and etc.
209 * @details Simplified macro to send a main log message using the current LOG_TAG.
211 * LOGD("app debug %d", num);
212 * LOGE("app error %d", num);
214 #ifdef TIZEN_DEBUG_ENABLE
215 #define LOGD(format, arg...) LOG_(LOG_ID_MAIN, DLOG_DEBUG, LOG_TAG, format, ##arg)
217 #define LOGD(format, arg...) NOP(format, ##arg)
219 #define LOGI(format, arg...) LOG_(LOG_ID_MAIN, DLOG_INFO, LOG_TAG, format, ##arg)
220 #define LOGW(format, arg...) LOG_(LOG_ID_MAIN, DLOG_WARN, LOG_TAG, format, ##arg)
221 #define LOGE(format, arg...) LOG_(LOG_ID_MAIN, DLOG_ERROR, LOG_TAG, format, ##arg)
222 #define LOGF(format, arg...) LOG_(LOG_ID_MAIN, DLOG_FATAL, LOG_TAG, format, ##arg)
225 * @brief For Framework and system etc.
226 * @details Simplified macro to send a system log message using the current LOG_TAG.
228 * SLOGD("system debug %d", num);
229 * SLOGE("system error %d", num);
231 #ifdef TIZEN_DEBUG_ENABLE
232 #define SLOGD(format, arg...) LOG_(LOG_ID_SYSTEM, DLOG_DEBUG, LOG_TAG, format, ##arg)
234 #define SLOGD(format, arg...) NOP(format, ##arg)
236 #define SLOGI(format, arg...) LOG_(LOG_ID_SYSTEM, DLOG_INFO, LOG_TAG, format, ##arg)
237 #define SLOGW(format, arg...) LOG_(LOG_ID_SYSTEM, DLOG_WARN, LOG_TAG, format, ##arg)
238 #define SLOGE(format, arg...) LOG_(LOG_ID_SYSTEM, DLOG_ERROR, LOG_TAG, format, ##arg)
239 #define SLOGF(format, arg...) LOG_(LOG_ID_SYSTEM, DLOG_FATAL, LOG_TAG, format, ##arg)
242 * @brief For Modem and radio etc.
243 * @details Simplified macro to send a radio log message using the current LOG_TAG.
245 * RLOGD("radio debug %d", num);
246 * RLOGE("radio error %d", num);
248 #ifdef TIZEN_DEBUG_ENABLE
249 #define RLOGD(format, arg...) LOG_(LOG_ID_RADIO, DLOG_DEBUG, LOG_TAG, format, ##arg)
251 #define RLOGD(format, arg...) NOP(format, ##arg)
253 #define RLOGI(format, arg...) LOG_(LOG_ID_RADIO, DLOG_INFO, LOG_TAG, format, ##arg)
254 #define RLOGW(format, arg...) LOG_(LOG_ID_RADIO, DLOG_WARN, LOG_TAG, format, ##arg)
255 #define RLOGE(format, arg...) LOG_(LOG_ID_RADIO, DLOG_ERROR, LOG_TAG, format, ##arg)
256 #define RLOGF(format, arg...) LOG_(LOG_ID_RADIO, DLOG_FATAL, LOG_TAG, format, ##arg)
259 * @brief For Tizen OSP Application macro.
261 #ifdef TIZEN_DEBUG_ENABLE
262 #define ALOGD(format, arg...) LOG_(LOG_ID_APPS, DLOG_DEBUG, LOG_TAG, format, ##arg)
264 #define ALOGD(format, arg...) NOP(format, ##arg)
266 #define ALOGI(format, arg...) LOG_(LOG_ID_APPS, DLOG_INFO, LOG_TAG, format, ##arg)
267 #define ALOGW(format, arg...) LOG_(LOG_ID_APPS, DLOG_WARN, LOG_TAG, format, ##arg)
268 #define ALOGE(format, arg...) LOG_(LOG_ID_APPS, DLOG_ERROR, LOG_TAG, format, ##arg)
269 #define ALOGF(format, arg...) LOG_(LOG_ID_APPS, DLOG_FATAL, LOG_TAG, format, ##arg)
273 * @brief Basic log message macro
274 * @details This macro allows you to specify a priority and a tag
275 * if you want to use this macro directly, you must add this messages for unity of messages.
276 * (LOG(prio, tag, "%s: %s(%d) > " format, __MODULE__, __func__, __LINE__, ##arg))
279 * #define MYMACRO(prio, tag, format, arg...) \
280 * LOG(prio, tag, format, ##arg)
282 * MYMACRO(LOG_DEBUG, MYTAG, "test mymacro %d", num);
286 #define LOG(priority, tag, format, arg...) LOG_(LOG_ID_MAIN, D##priority, tag, format, ##arg)
288 #define SLOG(priority, tag, format, arg...) LOG_(LOG_ID_SYSTEM, D##priority, tag, format, ##arg)
289 #define RLOG(priority, tag, format, arg...) LOG_(LOG_ID_RADIO, D##priority, tag, format, ##arg)
290 #define ALOG(priority, tag, format, arg...) LOG_(LOG_ID_APPS, D##priority, tag, format, ##arg)
294 #define LOG_VA(priority, tag, fmt, args) \
295 vprint_log(D##priority, tag, fmt, args)
296 #define ALOG_VA(priority, tag, fmt, args) \
297 vprint_apps_log(D##priority, tag, fmt, args)
298 #define RLOG_VA(priority, tag, fmt, args) \
299 vprint_radio_log(D##priority, tag, fmt, args)
300 #define SLOG_VA(priority, tag, fmt, args) \
301 vprint_system_log(D##priority, tag, fmt, args)
302 #define print_apps_log(prio, tag, fmt...) \
303 __dlog_print(LOG_ID_APPS, prio, tag, fmt)
304 #define vprint_apps_log(prio, tag, fmt...) \
305 __dlog_vprint(LOG_ID_APPS, prio, tag, fmt)
306 #define print_log(prio, tag, fmt...) \
307 __dlog_print(LOG_ID_MAIN, prio, tag, fmt)
308 #define vprint_log(prio, tag, fmt...) \
309 __dlog_vprint(LOG_ID_MAIN, prio, tag, fmt)
310 #define print_radio_log(prio, tag, fmt...)\
311 __dlog_print(LOG_ID_RADIO, prio, tag, fmt)
312 #define vprint_radio_log(prio, tag, fmt...) \
313 __dlog_vprint(LOG_ID_RADIO, prio, tag, fmt)
314 #define print_system_log(prio, tag, fmt...)\
315 __dlog_print(LOG_ID_SYSTEM, prio, tag, fmt)
316 #define vprint_system_log(prio, tag, fmt...) \
317 __dlog_vprint(LOG_ID_SYSTEM, prio, tag, fmt)
319 // ---------------------------------------------------------------------
320 // Don't use below macro no more!! It will be removed -- Verbose and Fatal priority macro will be removed --
321 #define COMPATIBILITY_ON
322 #ifdef COMPATIBILITY_ON
325 * @breif Conditional Macro.
326 * @remarks Don't use this macro. It's just compatibility.
327 * It will be deprecated.
329 #define LOGD_IF(cond, format, arg...) \
331 if (CONDITION(cond)) { \
332 LOGD(format, ##arg); \
335 #define LOGI_IF(cond, format, arg...) \
337 if (CONDITION(cond)) { \
338 LOGI(format, ##arg); \
341 #define LOGW_IF(cond, format, arg...) \
343 if (CONDITION(cond)) { \
344 LOGW(format, ##arg); \
347 #define LOGE_IF(cond, format, arg...) \
349 if (CONDITION(cond)) { \
350 LOGE(format, ##arg); \
353 #define LOGF_IF(cond, format, arg...) \
355 if (CONDITION(cond)) { \
356 LOGF(format, ##arg); \
359 #define SLOGD_IF(cond, format, arg...) \
361 if (CONDITION(cond)) { \
362 SLOGD(format, ##arg); \
365 #define SLOGI_IF(cond, format, arg...) \
367 if (CONDITION(cond)) { \
368 SLOGI(format, ##arg); \
371 #define SLOGW_IF(cond, format, arg...) \
373 if (CONDITION(cond)) { \
374 SLOGW(format, ##arg); \
377 #define SLOGE_IF(cond, format, arg...) \
379 if (CONDITION(cond)) { \
380 SLOGE(format, ##arg); \
383 #define SLOGF_IF(cond, format, arg...) \
385 if (CONDITION(cond)) { \
386 SLOGF(format, ##arg); \
389 #define RLOGD_IF(cond, format, arg...) \
391 if (CONDITION(cond)) { \
392 RLOGD(format, ##arg); \
395 #define RLOGI_IF(cond, format, arg...) \
397 if (CONDITION(cond)) { \
398 RLOGI(format, ##arg); \
401 #define RLOGW_IF(cond, format, arg...) \
403 if (CONDITION(cond)) { \
404 RLOGW(format, ##arg); \
407 #define RLOGE_IF(cond, format, arg...) \
409 if (CONDITION(cond)) { \
410 RLOGE(format, ##arg); \
413 #define RLOGF_IF(cond, format, arg...) \
415 if (CONDITION(cond)) { \
416 RLOGF(format, ##arg); \
419 #define LOG_ON() ({ do { } while (0); })
420 #define LOGV(format, arg...) NOP(format, ##arg)
421 #define SLOGV(format, arg...) NOP(format, ##arg)
422 #define RLOGV(format, arg...) NOP(format, ##arg)
423 #define ALOGV(format, arg...) NOP(format, ##arg)
424 #define LOGV_IF(cond, format, arg...) NOP(format, ##arg)
425 #define SLOGV_IF(cond, format, arg...) NOP(format, ##arg)
426 #define RLOGV_IF(cond, format, arg...) NOP(format, ##arg)
427 #define SECLOG(...) ({ do { } while (0); })
429 // ---------------------------------------------------------------------
432 * @addtogroup CAPI_SYSTEM_DLOG
436 * @brief Send log with priority and tag.
437 * @details for application
438 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
439 * @param[in] prio log_priority
441 * @param[in] fmt format string
442 * @return On success, the function returns the number of bytes written.
443 * On error, a negative errno-style error code
444 * @retval #DLOG_ERROR_INVALID_PARAMETER Invalid parameter
445 * @retval #DLOG_ERROR_NOT_PERMITTED Operation not permitted
454 char string[] = "test dlog";
456 dlog_print(DLOG_INFO, "USR_TAG", "test dlog");
457 dlog_print(DLOG_INFO, "USR_TAG", "%s, %d", string, integer);
462 int dlog_print(log_priority prio, const char *tag, const char *fmt, ...);
465 * @brief Send log with priority, tag and va_list.
466 * @details for application
467 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
468 * @param[in] prio log_priority
470 * @param[in] fmt format string
471 * @param[in] ap va_list
472 * @return On success, the function returns the number of bytes written.
473 * On error, a negative errno-style error code
474 * @retval #DLOG_ERROR_INVALID_PARAMETER Invalid parameter
475 * @retval #DLOG_ERROR_NOT_PERMITTED Operation not permitted
481 void my_debug_print(char *format, ...)
485 va_start(ap, format);
486 dlog_vprint(DLOG_INFO, "USR_TAG", format, ap);
492 my_debug_print("%s", "test dlog");
493 my_debug_print("%s, %d", "test dlog", 21);
498 int dlog_vprint(log_priority prio, const char *tag, const char *fmt, va_list ap);
505 * The stuff in the rest of this file should not be used directly.
510 * @details Use LOG(), SLOG(), RLOG() family
511 * not to use __dlog_print() directly
512 * @remarks Must not use this API directly. use macros instead.
513 * @param[in] log_id log device id
514 * @param[in] prio priority
516 * @param[in] fmt format string
517 * @return Operation result
518 * @retval 0>= Success
524 #define LOG_TAG USR_TAG
526 __dlog_print(LOG_ID_MAIN, DLOG_INFO, USR_TAG, "you must not use this API directly");
529 int __dlog_print(log_id_t log_id, int prio, const char *tag, const char *fmt, ...);
533 * @brief Send log with va_list.
534 * @details Use LOG_VA(), SLOG_VA(), RLOG_VA() family
535 not to use __dlog_vprint() directly
536 * @remarks Must not use this API directly. use macros instead.
537 * @param[in] log_id log device id
538 * @param[in] prio priority
540 * @param[in] fmt format string
541 * @param[in] ap va_list
542 * @return Operation result
543 * @retval 0>= Success
549 #define LOG_TAG USR_TAG
551 __dlog_vprint(LOG_ID_MAIN, DLOG_INFO, USR_TAG, "you must not use this API directly", ap);
554 int __dlog_vprint(log_id_t log_id, int prio, const char *tag, const char *fmt, va_list ap);
557 #endif /* __cplusplus */