2 * Copyright (C) 2005 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
21 * @brief This file is the header file of interface of dlog.
26 * @addtogroup APPLICATION_FRAMEWORK
43 #endif /* __cplusplus */
46 * Normally we strip LOGV (VERBOSE messages) from release builds.
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.
66 * log priority values, in ascending priority order.
88 #define CONDITION(cond) (__builtin_expect((cond)!=0, 0))
90 // ---------------------------------------------------------------------
93 * Simplified macro to send a verbose log message using the current LOG_TAG.
97 #define LOGV(...) ((void)0)
99 #define LOGV(...) ((void)LOG(LOG_VERBOSE, LOG_TAG, __VA_ARGS__))
105 * Simplified macro to send a conditional verbose log message using the current LOG_TAG.
109 #define LOGV_IF(cond, ...) ((void)0)
111 #define LOGV_IF(cond, ...) \
112 ( (CONDITION(cond)) \
113 ? ((void)LOG(LOG_VERBOSE, LOG_TAG, __VA_ARGS__)) \
119 * Simplified macro to send a debug log message using the current LOG_TAG.
122 #define LOGD(...) ((void)LOG(LOG_DEBUG, LOG_TAG, __VA_ARGS__))
126 * Simplified macro to send a conditional debug log message using the current LOG_TAG.
129 #define LOGD_IF(cond, ...) \
130 ( (CONDITION(cond)) \
131 ? ((void)LOG(LOG_DEBUG, LOG_TAG, __VA_ARGS__)) \
136 * Simplified macro to send an info log message using the current LOG_TAG.
139 #define LOGI(...) ((void)LOG(LOG_INFO, LOG_TAG, __VA_ARGS__))
143 * Simplified macro to send a conditional info log message using the current LOG_TAG.
146 #define LOGI_IF(cond, ...) \
147 ( (CONDITION(cond)) \
148 ? ((void)LOG(LOG_INFO, LOG_TAG, __VA_ARGS__)) \
153 * Simplified macro to send a warning log message using the current LOG_TAG.
156 #define LOGW(...) ((void)LOG(LOG_WARN, LOG_TAG, __VA_ARGS__))
160 * Simplified macro to send a conditional warning log message using the current LOG_TAG.
163 #define LOGW_IF(cond, ...) \
164 ( (CONDITION(cond)) \
165 ? ((void)LOG(LOG_WARN, LOG_TAG, __VA_ARGS__)) \
170 * Simplified macro to send an error log message using the current LOG_TAG.
173 #define LOGE(...) ((void)LOG(LOG_ERROR, LOG_TAG, __VA_ARGS__))
177 * Simplified macro to send a conditional error log message using the current LOG_TAG.
180 #define LOGE_IF(cond, ...) \
181 ( (CONDITION(cond)) \
182 ? ((void)LOG(LOG_ERROR, LOG_TAG, __VA_ARGS__)) \
186 // ---------------------------------------------------------------------
189 * Simplified macro to send a verbose radio log message using the current LOG_TAG.
193 #define RLOGV(...) ((void)0)
195 #define RLOGV(...) ((void)RLOG(LOG_VERBOSE, LOG_TAG, __VA_ARGS__))
200 * Simplified macro to send a conditional verbose radio log message using the current LOG_TAG.
204 #define RLOGV_IF(cond, ...) ((void)0)
206 #define RLOGV_IF(cond, ...) \
207 ( (CONDITION(cond)) \
208 ? ((void)RLOG(LOG_VERBOSE, LOG_TAG, __VA_ARGS__)) \
214 * Simplified macro to send a debug radio log message using the current LOG_TAG.
217 #define RLOGD(...) ((void)RLOG(LOG_DEBUG, LOG_TAG, __VA_ARGS__))
221 * Simplified macro to send a conditional debug radio log message using the current LOG_TAG.
224 #define RLOGD_IF(cond, ...) \
225 ( (CONDITION(cond)) \
226 ? ((void)RLOG(LOG_DEBUG, LOG_TAG, __VA_ARGS__)) \
231 * Simplified macro to send an info radio log message using the current LOG_TAG.
234 #define RLOGI(...) ((void)RLOG(LOG_INFO, LOG_TAG, __VA_ARGS__))
238 * Simplified macro to send a conditional info radio log message using the current LOG_TAG.
241 #define RLOGI_IF(cond, ...) \
242 ( (CONDITION(cond)) \
243 ? ((void)RLOG(LOG_INFO, LOG_TAG, __VA_ARGS__)) \
248 * Simplified macro to send a warning radio log message using the current LOG_TAG.
251 #define RLOGW(...) ((void)RLOG(LOG_WARN, LOG_TAG, __VA_ARGS__))
255 * Simplified macro to send a conditional warning radio log message using the current LOG_TAG.
258 #define RLOGW_IF(cond, ...) \
259 ( (CONDITION(cond)) \
260 ? ((void)RLOG(LOG_WARN, LOG_TAG, __VA_ARGS__)) \
265 * Simplified macro to send an error radio log message using the current LOG_TAG.
268 #define RLOGE(...) ((void)RLOG(LOG_ERROR, LOG_TAG, __VA_ARGS__))
272 * Simplified macro to send a conditional error radio log message using the current LOG_TAG.
275 #define RLOGE_IF(cond, ...) \
276 ( (CONDITION(cond)) \
277 ? ((void)RLOG(LOG_ERROR, LOG_TAG, __VA_ARGS__)) \
281 // ---------------------------------------------------------------------
284 * Simplified macro to send a verbose system log message using the current LOG_TAG.
288 #define SLOGV(...) ((void)0)
290 #define SLOGV(...) ((void)SLOG(LOG_VERBOSE, LOG_TAG, __VA_ARGS__))
295 * Simplified macro to send a conditional verbose system log message using the current LOG_TAG.
299 #define SLOGV_IF(cond, ...) ((void)0)
301 #define SLOGV_IF(cond, ...) \
302 ( (CONDITION(cond)) \
303 ? ((void)SLOG(LOG_VERBOSE, LOG_TAG, __VA_ARGS__)) \
309 * Simplified macro to send a debug system log message using the current LOG_TAG.
312 #define SLOGD(...) ((void)SLOG(LOG_DEBUG, LOG_TAG, __VA_ARGS__))
316 * Simplified macro to send a conditional debug system log message using the current LOG_TAG.
319 #define SLOGD_IF(cond, ...) \
320 ( (CONDITION(cond)) \
321 ? ((void)SLOG(LOG_DEBUG, LOG_TAG, __VA_ARGS__)) \
326 * Simplified macro to send an info system log message using the current LOG_TAG.
329 #define SLOGI(...) ((void)SLOG(LOG_INFO, LOG_TAG, __VA_ARGS__))
333 * Simplified macro to send a conditional info system log message using the current LOG_TAG.
336 #define SLOGI_IF(cond, ...) \
337 ( (CONDITION(cond)) \
338 ? ((void)SLOG(LOG_INFO, LOG_TAG, __VA_ARGS__)) \
343 * Simplified macro to send a warning system log message using the current LOG_TAG.
346 #define SLOGW(...) ((void)SLOG(LOG_WARN, LOG_TAG, __VA_ARGS__))
350 * Simplified macro to send a conditional warning system log message using the current LOG_TAG.
353 #define SLOGW_IF(cond, ...) \
354 ( (CONDITION(cond)) \
355 ? ((void)SLOG(LOG_WARN, LOG_TAG, __VA_ARGS__)) \
360 * Simplified macro to send an error system log message using the current LOG_TAG.
363 #define SLOGE(...) ((void)SLOG(LOG_ERROR, LOG_TAG, __VA_ARGS__))
367 * Simplified macro to send a conditional error system log message using the current LOG_TAG.
370 #define SLOGE_IF(cond, ...) \
371 ( (CONDITION(cond)) \
372 ? ((void)SLOG(LOG_ERROR, LOG_TAG, __VA_ARGS__)) \
376 // ---------------------------------------------------------------------
379 * Simplified macro to send a verbose log message using the current LOG_TAG.
383 #define ALOGV(...) ((void)0)
385 #define ALOGV(...) ((void)ALOG(LOG_VERBOSE, LOG_TAG, __VA_ARGS__))
391 * Simplified macro to send a conditional verbose log message using the current LOG_TAG.
395 #define ALOGV_IF(cond, ...) ((void)0)
397 #define ALOGV_IF(cond, ...) \
398 ( (CONDITION(cond)) \
399 ? ((void)ALOG(LOG_VERBOSE, LOG_TAG, __VA_ARGS__)) \
405 * Simplified macro to send a debug log message using the current LOG_TAG.
408 #define ALOGD(...) ((void)ALOG(LOG_DEBUG, LOG_TAG, __VA_ARGS__))
412 * Simplified macro to send a conditional debug log message using the current LOG_TAG.
415 #define ALOGD_IF(cond, ...) \
416 ( (CONDITION(cond)) \
417 ? ((void)ALOG(LOG_DEBUG, LOG_TAG, __VA_ARGS__)) \
422 * Simplified macro to send an info log message using the current LOG_TAG.
425 #define ALOGI(...) ((void)ALOG(LOG_INFO, LOG_TAG, __VA_ARGS__))
429 * Simplified macro to send a conditional info log message using the current LOG_TAG.
432 #define ALOGI_IF(cond, ...) \
433 ( (CONDITION(cond)) \
434 ? ((void)ALOG(LOG_INFO, LOG_TAG, __VA_ARGS__)) \
439 * Simplified macro to send a warning log message using the current LOG_TAG.
442 #define ALOGW(...) ((void)ALOG(LOG_WARN, LOG_TAG, __VA_ARGS__))
446 * Simplified macro to send a conditional warning log message using the current LOG_TAG.
449 #define ALOGW_IF(cond, ...) \
450 ( (CONDITION(cond)) \
451 ? ((void)ALOG(LOG_WARN, LOG_TAG, __VA_ARGS__)) \
456 * Simplified macro to send an error log message using the current LOG_TAG.
459 #define ALOGE(...) ((void)ALOG(LOG_ERROR, LOG_TAG, __VA_ARGS__))
463 * Simplified macro to send a conditional error log message using the current LOG_TAG.
466 #define ALOGE_IF(cond, ...) \
467 ( (CONDITION(cond)) \
468 ? ((void)ALOG(LOG_ERROR, LOG_TAG, __VA_ARGS__)) \
471 // TODO : support fatal log
473 // ---------------------------------------------------------------------
476 * Basic log message macro that allows you to specify a priority and a tag
479 * LOG(DLOG_WARN, NULL, "Failed with error %d", errno);
481 * The second argument may be NULL or "" to indicate the "global" tag.
483 * Future work : we want to put filename and line number automatically only when debug build mode
486 #define LOG(priority, tag, ...) \
487 print_log(D##priority, tag, __VA_ARGS__)
491 * Log macro that allows you to pass in a varargs ("args" is a va_list).
494 #define LOG_VA(priority, tag, fmt, args) \
495 vprint_log(D##priority, tag, fmt, args)
499 #define ALOG(priority, tag, ...) \
500 print_apps_log(D##priority, tag, __VA_ARGS__)
503 * Log macro that allows you to pass in a varargs ("args" is a va_list).
506 #define ALOG_VA(priority, tag, fmt, args) \
507 vprint_apps_log(D##priority, tag, fmt, args)
511 * Basic radio log macro that allows you to specify a priority and a tag.
514 #define RLOG(priority, tag, ...) \
515 print_radio_log(D##priority, tag, __VA_ARGS__)
519 * Radio log macro that allows you to pass in a varargs ("args" is a va_list).
522 #define RLOG_VA(priority, tag, fmt, args) \
523 vprint_radio_log(D##priority, tag, fmt, args)
527 * Basic system log macro that allows you to specify a priority and a tag.
530 #define SLOG(priority, tag, ...) \
531 print_system_log(D##priority, tag, __VA_ARGS__)
535 * System log macro that allows you to pass in a varargs ("args" is a va_list).
538 #define SLOG_VA(priority, tag, fmt, args) \
539 vprint_system_log(D##priority, tag, fmt, args)
544 * ===========================================================================
546 * The stuff in the rest of this file should not be used directly.
549 #define print_apps_log(prio, tag, fmt...) \
550 __dlog_print(LOG_ID_APPS, prio, tag, fmt)
552 #define vprint_apps_log(prio, tag, fmt...) \
553 __dlog_vprint(LOG_ID_APPS, prio, tag, fmt)
555 #define print_log(prio, tag, fmt...) \
556 __dlog_print(LOG_ID_MAIN, prio, tag, fmt)
558 #define vprint_log(prio, tag, fmt...) \
559 __dlog_vprint(LOG_ID_MAIN, prio, tag, fmt)
561 #define print_radio_log(prio, tag, fmt...)\
562 __dlog_print(LOG_ID_RADIO, prio, tag, fmt)
564 #define vprint_radio_log(prio, tag, fmt...) \
565 __dlog_vprint(LOG_ID_RADIO, prio, tag, fmt)
567 #define print_system_log(prio, tag, fmt...)\
568 __dlog_print(LOG_ID_SYSTEM, prio, tag, fmt)
570 #define vprint_system_log(prio, tag, fmt...) \
571 __dlog_vprint(LOG_ID_SYSTEM, prio, tag, fmt)
574 * @brief send log. must specify log_id ,priority, tag and format string.
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
582 * @param[in] fmt format string
583 * @return Operation result
584 * @retval 0>= Success
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
591 __dlog_print(LOG_ID_MAIN, DLOG_INFO, USR_TAG, "you must not use this API directly");
594 int __dlog_print(log_id_t log_id, int prio, const char *tag, const char *fmt, ...);
597 * @brief send log with va_list. must specify log_id ,priority, tag and format string.
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
605 * @param[in] fmt format string
606 * @param[in] ap va_list
607 * @return Operation result
608 * @retval 0>= Success
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
615 __dlog_vprint(LOG_ID_MAIN, DLOG_INFO, USR_TAG, "you must not use this API directly", ap);
618 int __dlog_vprint(log_id_t log_id, int prio, const char *tag, const char *fmt, va_list ap);
622 #endif /* __cplusplus */