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.
21 * @brief This file is the header file of interface of dlog.
24 * @addtogroup APPLICATION_FRAMEWORK
40 #endif /* __cplusplus */
43 * Normally we strip LOGV (VERBOSE messages) from release builds.
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.
62 #define LOG_ON() _get_logging_on()
65 #define __MODULE__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__)
68 * log priority values, in ascending priority order.
90 #define CONDITION(cond) (__builtin_expect((cond) != 0, 0))
92 // ---------------------------------------------------------------------
94 * Simplified macro to send a verbose log message using the current LOG_TAG.
100 #define LOGV(format, arg...) \
101 (LOG_ON() ? (LOG(LOG_VERBOSE, LOG_TAG, "%s:%s(%d)>"format, __MODULE__, __func__, __LINE__, ##arg)) : (0))
105 * Simplified macro to send a conditional verbose log message using the current LOG_TAG.
109 #define LOGV_IF(cond, format, arg...) (0)
111 #define LOGV_IF(cond, format, arg...) \
112 (((CONDITION(cond)) && (LOG_ON())) ? \
113 (LOG(LOG_VERBOSE, LOG_TAG, "%s:%s(%d)>"format, __MODULE__, __func__, __LINE__, ##arg)) : (0))
117 * Simplified macro to send a debug log message using the current LOG_TAG.
120 #define LOGD(format, arg...) \
121 (LOG_ON() ? (LOG(LOG_DEBUG, LOG_TAG, "%s:%s(%d)>"format, __MODULE__, __func__, __LINE__, ##arg)) : (0))
124 * Simplified macro to send a conditional verbose log message using the current LOG_TAG.
127 #define LOGD_IF(cond, format, arg...) \
128 (((CONDITION(cond)) && (LOG_ON())) ? \
129 (LOG(LOG_DEBUG, LOG_TAG, "%s:%s(%d)>"format, __MODULE__, __func__, __LINE__, ##arg)) : (0))
133 * Simplified macro to send an info log message using the current LOG_TAG.
136 #define LOGI(format, arg...) \
137 (LOG_ON() ? (LOG(LOG_INFO, LOG_TAG, "%s:%s(%d)>"format, __MODULE__, __func__, __LINE__, ##arg)) : (0))
140 * Simplified macro to send a conditional verbose log message using the current LOG_TAG.
143 #define LOGI_IF(cond, format, arg...) \
144 (((CONDITION(cond)) && (LOG_ON())) ? \
145 (LOG(LOG_INFO, LOG_TAG, "%s:%s(%d)>"format, __MODULE__, __func__, __LINE__, ##arg)) : (0))
149 * Simplified macro to send a warning log message using the current LOG_TAG.
152 #define LOGW(format, arg...) \
153 (LOG_ON() ? (LOG(LOG_WARN, LOG_TAG, "%s:%s(%d)>"format, __MODULE__, __func__, __LINE__, ##arg)) : (0))
156 * Simplified macro to send a conditional verbose log message using the current LOG_TAG.
159 #define LOGW_IF(cond, format, arg...) \
160 (((CONDITION(cond)) && (LOG_ON())) ? \
161 (LOG(LOG_WARN, LOG_TAG, "%s:%s(%d)>"format, __MODULE__, __func__, __LINE__, ##arg)) : (0))
165 * Simplified macro to send an error log message using the current LOG_TAG.
168 #define LOGE(format, arg...) \
169 (LOG_ON() ? (LOG(LOG_ERROR, LOG_TAG, "%s:%s(%d)>"format, __MODULE__, __func__, __LINE__, ##arg)) : (0))
172 * Simplified macro to send a conditional verbose log message using the current LOG_TAG.
175 #define LOGE_IF(cond, format, arg...) \
176 (((CONDITION(cond)) && (LOG_ON())) ? \
177 (LOG(LOG_ERROR, LOG_TAG, "%s:%s(%d)>"format, __MODULE__, __func__, __LINE__, ##arg)) : (0))
180 * Simplified macro to send an error log message using the current LOG_TAG.
183 #define LOGF(format, arg...) \
184 (LOG_ON() ? (LOG(LOG_FATAL, LOG_TAG, "%s:%s(%d)>"format, __MODULE__, __func__, __LINE__, ##arg)) : (0))
187 * Simplified macro to send a conditional verbose log message using the current LOG_TAG.
190 #define LOGF_IF(cond, format, arg...) \
191 (((CONDITION(cond)) && (LOG_ON())) ? \
192 (LOG(LOG_FATAL, LOG_TAG, "%s:%s(%d)>"format, __MODULE__, __func__, __LINE__, ##arg)) : (0))
195 // ---------------------------------------------------------------------
197 * Simplified radio macro to send a verbose log message using the current LOG_TAG.
201 #define RLOGV(...) (0)
203 #define RLOGV(format, arg...) \
204 (LOG_ON() ? (RLOG(LOG_VERBOSE, LOG_TAG, "%s:%s(%d)>"format, __MODULE__, __func__, __LINE__, ##arg)) : (0))
208 * Simplified radio macro to send a conditional verbose log message using the current LOG_TAG.
212 #define RLOGV_IF(cond, format, arg...) (0)
214 #define RLOGV_IF(cond, format, arg...) \
215 (((CONDITION(cond)) && (LOG_ON())) ? \
216 (RLOG(LOG_VERBOSE, LOG_TAG, "%s:%s(%d)>"format, __MODULE__, __func__, __LINE__, ##arg)) : (0))
221 * Simplified radio macro to send a debug log message using the current LOG_TAG.
224 #define RLOGD(format, arg...) \
225 (LOG_ON() ? (RLOG(LOG_DEBUG, LOG_TAG, "%s:%s(%d)>"format, __MODULE__, __func__, __LINE__, ##arg)) : (0))
228 * Simplified radio macro to send a conditional verbose log message using the current LOG_TAG.
231 #define RLOGD_IF(cond, format, arg...) \
232 (((CONDITION(cond)) && (LOG_ON())) ? \
233 (RLOG(LOG_DEBUG, LOG_TAG, "%s:%s(%d)>"format, __MODULE__, __func__, __LINE__, ##arg)) : (0))
237 * Simplified radio macro to send an info log message using the current LOG_TAG.
240 #define RLOGI(format, arg...) \
241 (LOG_ON() ? (RLOG(LOG_INFO, LOG_TAG, "%s:%s(%d)>"format, __MODULE__, __func__, __LINE__, ##arg)) : (0))
244 * Simplified radio macro to send a conditional verbose log message using the current LOG_TAG.
247 #define RLOGI_IF(cond, format, arg...) \
248 (((CONDITION(cond)) && (LOG_ON())) ? \
249 (RLOG(LOG_INFO, LOG_TAG, "%s:%s(%d)>"format, __MODULE__, __func__, __LINE__, ##arg)) : (0))
253 * Simplified radio macro to send a warning log message using the current LOG_TAG.
256 #define RLOGW(format, arg...) \
257 (LOG_ON() ? (RLOG(LOG_WARN, LOG_TAG, "%s:%s(%d)>"format, __MODULE__, __func__, __LINE__, ##arg)) : (0))
260 * Simplified radio macro to send a conditional verbose log message using the current LOG_TAG.
263 #define RLOGW_IF(cond, format, arg...) \
264 (((CONDITION(cond)) && (LOG_ON())) ? \
265 (RLOG(LOG_WARN, LOG_TAG, "%s:%s(%d)>"format, __MODULE__, __func__, __LINE__, ##arg)) : (0))
269 * Simplified radio macro to send an error log message using the current LOG_TAG.
272 #define RLOGE(format, arg...) \
273 (LOG_ON() ? (RLOG(LOG_ERROR, LOG_TAG, "%s:%s(%d)>"format, __MODULE__, __func__, __LINE__, ##arg)) : (0))
276 * Simplified radio macro to send a conditional verbose log message using the current LOG_TAG.
279 #define RLOGE_IF(cond, format, arg...) \
280 (((CONDITION(cond)) && (LOG_ON())) ? \
281 (RLOG(LOG_ERROR, LOG_TAG, "%s:%s(%d)>"format, __MODULE__, __func__, __LINE__, ##arg)) : (0))
284 * Simplified radio macro to send an error log message using the current LOG_TAG.
287 #define RLOGF(format, arg...) \
288 (LOG_ON() ? (RLOG(LOG_FATAL, LOG_TAG, "%s:%s(%d)>"format, __MODULE__, __func__, __LINE__, ##arg)) : (0))
291 * Simplified radio macro to send a conditional verbose log message using the current LOG_TAG.
294 #define RLOGF_IF(cond, format, arg...) \
295 (((CONDITION(cond)) && (LOG_ON())) ? \
296 (RLOG(LOG_FATAL, LOG_TAG, "%s:%s(%d)>"format, __MODULE__, __func__, __LINE__, ##arg)) : (0))
300 // ---------------------------------------------------------------------
302 * Simplified system macro to send a verbose log message using the current LOG_TAG.
306 #define SLOGV(...) (0)
308 #define SLOGV(format, arg...) \
309 (LOG_ON() ? (SLOG(LOG_VERBOSE, LOG_TAG, "%s:%s(%d)>"format, __MODULE__, __func__, __LINE__, ##arg)) : (0))
313 * Simplified macro to send a conditional verbose log message using the current LOG_TAG.
317 #define SLOGV_IF(cond, format, arg...) (0)
319 #define SLOGV_IF(cond, format, arg...) \
320 (((CONDITION(cond)) && (LOG_ON())) ? \
321 (SLOG(LOG_VERBOSE, LOG_TAG, "%s:%s(%d)>"format, __MODULE__, __func__, __LINE__, ##arg)) : (0))
326 * Simplified system macro to send a debug log message using the current LOG_TAG.
329 #define SLOGD(format, arg...) \
330 (LOG_ON() ? (SLOG(LOG_DEBUG, LOG_TAG, "%s:%s(%d)>"format, __MODULE__, __func__, __LINE__, ##arg)) : (0))
333 * Simplified system macro to send a conditional verbose log message using the current LOG_TAG.
336 #define SLOGD_IF(cond, format, arg...) \
337 (((CONDITION(cond)) && (LOG_ON())) ? \
338 (SLOG(LOG_DEBUG, LOG_TAG, "%s:%s(%d)>"format, __MODULE__, __func__, __LINE__, ##arg)) : (0))
342 * Simplified system macro to send an info log message using the current LOG_TAG.
345 #define SLOGI(format, arg...) \
346 (LOG_ON() ? (SLOG(LOG_INFO, LOG_TAG, "%s:%s(%d)>"format, __MODULE__, __func__, __LINE__, ##arg)) : (0))
349 * Simplified system macro to send a conditional verbose log message using the current LOG_TAG.
352 #define SLOGI_IF(cond, format, arg...) \
353 (((CONDITION(cond)) && (LOG_ON())) ? \
354 (SLOG(LOG_INFO, LOG_TAG, "%s:%s(%d)>"format, __MODULE__, __func__, __LINE__, ##arg)) : (0))
358 * Simplified system macro to send a warning log message using the current LOG_TAG.
361 #define SLOGW(format, arg...) \
362 (LOG_ON() ? (SLOG(LOG_WARN, LOG_TAG, "%s:%s(%d)>"format, __MODULE__, __func__, __LINE__, ##arg)) : (0))
365 * Simplified system macro to send a conditional verbose log message using the current LOG_TAG.
368 #define SLOGW_IF(cond, format, arg...) \
369 (((CONDITION(cond)) && (LOG_ON())) ? \
370 (SLOG(LOG_WARN, LOG_TAG, "%s:%s(%d)>"format, __MODULE__, __func__, __LINE__, ##arg)) : (0))
374 * Simplified system macro to send an error log message using the current LOG_TAG.
377 #define SLOGE(format, arg...) \
378 (LOG_ON() ? (SLOG(LOG_ERROR, LOG_TAG, "%s:%s(%d)>"format, __MODULE__, __func__, __LINE__, ##arg)) : (0))
381 * Simplified system macro to send a conditional verbose log message using the current LOG_TAG.
384 #define SLOGE_IF(cond, format, arg...) \
385 (((CONDITION(cond)) && (LOG_ON())) ? \
386 (SLOG(LOG_ERROR, LOG_TAG, "%s:%s(%d)>"format, __MODULE__, __func__, __LINE__, ##arg)) : (0))
389 * Simplified system macro to send an error log message using the current LOG_TAG.
392 #define SLOGF(format, arg...) \
393 (LOG_ON() ? (SLOG(LOG_FATAL, LOG_TAG, "%s:%s(%d)>"format, __MODULE__, __func__, __LINE__, ##arg)) : (0))
396 * Simplified system macro to send a conditional verbose log message using the current LOG_TAG.
399 #define SLOGF_IF(cond, format, arg...) \
400 (((CONDITION(cond)) && (LOG_ON())) ? \
401 (SLOG(LOG_FATAL, LOG_TAG, "%s:%s(%d)>"format, __MODULE__, __func__, __LINE__, ##arg)) : (0))
404 // ---------------------------------------------------------------------
407 * Simplified macro to send a verbose log message using the current LOG_TAG.
411 #define ALOGV(...) (0)
413 #define ALOGV(...) (ALOG(LOG_VERBOSE, LOG_TAG, __VA_ARGS__))
417 * Simplified macro to send a debug log message using the current LOG_TAG.
420 #define ALOGD(...) (ALOG(LOG_DEBUG, LOG_TAG, __VA_ARGS__))
423 * Simplified macro to send an info log message using the current LOG_TAG.
426 #define ALOGI(...) (ALOG(LOG_INFO, LOG_TAG, __VA_ARGS__))
429 * Simplified macro to send a warning log message using the current LOG_TAG.
432 #define ALOGW(...) (ALOG(LOG_WARN, LOG_TAG, __VA_ARGS__))
435 * Simplified macro to send an error log message using the current LOG_TAG.
438 #define ALOGE(...) (ALOG(LOG_ERROR, LOG_TAG, __VA_ARGS__))
441 // ---------------------------------------------------------------------
443 * Basic log message macro that allows you to specify a priority and a tag
446 * LOG(DLOG_WARN, NULL, "Failed with error %d", errno);
448 * The second argument may be NULL or "" to indicate the "global" tag.
450 * Future work : we want to put filename and line number automatically only when debug build mode
453 #define LOG(priority, tag, ...) \
454 print_log(D##priority, tag, __VA_ARGS__)
458 * Log macro that allows you to pass in a varargs ("args" is a va_list).
461 #define LOG_VA(priority, tag, fmt, args) \
462 vprint_log(D##priority, tag, fmt, args)
466 #define ALOG(priority, tag, ...) \
467 print_apps_log(D##priority, tag, __VA_ARGS__)
470 * Log macro that allows you to pass in a varargs ("args" is a va_list).
473 #define ALOG_VA(priority, tag, fmt, args) \
474 vprint_apps_log(D##priority, tag, fmt, args)
478 * Basic radio log macro that allows you to specify a priority and a tag.
481 #define RLOG(priority, tag, ...) \
482 print_radio_log(D##priority, tag, __VA_ARGS__)
485 * Radio log macro that allows you to pass in a varargs ("args" is a va_list).
488 #define RLOG_VA(priority, tag, fmt, args) \
489 vprint_radio_log(D##priority, tag, fmt, args)
493 * Basic system log macro that allows you to specify a priority and a tag.
496 #define SLOG(priority, tag, ...) \
497 print_system_log(D##priority, tag, __VA_ARGS__)
501 * System log macro that allows you to pass in a varargs ("args" is a va_list).
504 #define SLOG_VA(priority, tag, fmt, args) \
505 vprint_system_log(D##priority, tag, fmt, args)
510 * ===========================================================================
512 * The stuff in the rest of this file should not be used directly.
515 #define print_apps_log(prio, tag, fmt...) \
516 __dlog_print(LOG_ID_APPS, prio, tag, fmt)
518 #define vprint_apps_log(prio, tag, fmt...) \
519 __dlog_vprint(LOG_ID_APPS, prio, tag, fmt)
521 #define print_log(prio, tag, fmt...) \
522 __dlog_print(LOG_ID_MAIN, prio, tag, fmt)
524 #define vprint_log(prio, tag, fmt...) \
525 __dlog_vprint(LOG_ID_MAIN, prio, tag, fmt)
527 #define print_radio_log(prio, tag, fmt...)\
528 __dlog_print(LOG_ID_RADIO, prio, tag, fmt)
530 #define vprint_radio_log(prio, tag, fmt...) \
531 __dlog_vprint(LOG_ID_RADIO, prio, tag, fmt)
533 #define print_system_log(prio, tag, fmt...)\
534 __dlog_print(LOG_ID_SYSTEM, prio, tag, fmt)
536 #define vprint_system_log(prio, tag, fmt...) \
537 __dlog_vprint(LOG_ID_SYSTEM, prio, tag, fmt)
540 * @brief send log. must specify log_id ,priority, tag and format string.
544 * @remarks you must not use this API directly. use macros instead.
545 * @param[in] log_id log device id
546 * @param[in] prio priority
548 * @param[in] fmt format string
549 * @return Operation result
550 * @retval 0>= Success
553 // you have to use LOG(), SLOG(), RLOG() family not to use __dlog_print() directly
554 // so below example is just for passing Documentation Verification !!!
555 #define LOG_TAG USR_TAG
557 __dlog_print(LOG_ID_MAIN, DLOG_INFO, USR_TAG, "you must not use this API directly");
560 int __dlog_print(log_id_t log_id, int prio, const char *tag, const char *fmt, ...);
563 * @brief send log with va_list. must specify log_id ,priority, tag and format string.
567 * @remarks you must not use this API directly. use macros instead.
568 * @param[in] log_id log device id
569 * @param[in] prio priority
571 * @param[in] fmt format string
572 * @param[in] ap va_list
573 * @return Operation result
574 * @retval 0>= Success
577 // you have to use LOG_VA(), SLOG_VA(), RLOG_VA() family not to use __dlog_print() directly
578 // so below example is just for passing Documentation Verification !!!
579 #define LOG_TAG USR_TAG
581 __dlog_vprint(LOG_ID_MAIN, DLOG_INFO, USR_TAG, "you must not use this API directly", ap);
584 int __dlog_vprint(log_id_t log_id, int prio, const char *tag, const char *fmt, va_list ap);
585 int _get_logging_on(void);
589 #endif /* __cplusplus */