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.
19 * @brief This file is the header file of interface of dlog.
22 * @addtogroup APPLICATION_FRAMEWORK
38 #endif /* __cplusplus */
41 * Normally we strip LOGV (VERBOSE messages) from release builds.
52 * This is the local tag used for the following simplified
53 * logging macros. You can change this preprocessor definition
54 * before using the other macros to change the tag.
60 #define LOG_ON() _get_logging_on()
63 #define __MODULE__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__)
66 * log priority values, in ascending priority order.
88 #define CONDITION(cond) (__builtin_expect((cond) != 0, 0))
90 // ---------------------------------------------------------------------
92 * Simplified macro to send a verbose log message using the current LOG_TAG.
98 #define LOGV(format, arg...) \
99 (LOG_ON() ? (LOG(LOG_VERBOSE, LOG_TAG, "%s:%s(%d)>"format, __MODULE__, __func__, __LINE__, ##arg)) : (0))
103 * Simplified macro to send a conditional verbose log message using the current LOG_TAG.
107 #define LOGV_IF(cond, ...) (0)
109 #define LOGV_IF(cond, ...) \
110 (((CONDITION(cond)) && (LOG_ON())) ? \
111 (LOG(LOG_VERBOSE, LOG_TAG, "%s:%s(%d)>"format, __MODULE__, __func__, __LINE__, ##arg)) : (0))
115 * Simplified macro to send a debug log message using the current LOG_TAG.
118 #define LOGD(format, arg...) \
119 (LOG_ON() ? (LOG(LOG_DEBUG, LOG_TAG, "%s:%s(%d)>"format, __MODULE__, __func__, __LINE__, ##arg)) : (0))
122 * Simplified macro to send a conditional verbose log message using the current LOG_TAG.
125 #define LOGD_IF(cond, ...) \
126 (((CONDITION(cond)) && (LOG_ON())) ? \
127 (LOG(LOG_DEBUG, LOG_TAG, "%s:%s(%d)>"format, __MODULE__, __func__, __LINE__, ##arg)) : (0))
131 * Simplified macro to send an info log message using the current LOG_TAG.
134 #define LOGI(format, arg...) \
135 (LOG_ON() ? (LOG(LOG_INFO, LOG_TAG, "%s:%s(%d)>"format, __MODULE__, __func__, __LINE__, ##arg)) : (0))
138 * Simplified macro to send a conditional verbose log message using the current LOG_TAG.
141 #define LOGI_IF(cond, ...) \
142 (((CONDITION(cond)) && (LOG_ON())) ? \
143 (LOG(LOG_INFO, LOG_TAG, "%s:%s(%d)>"format, __MODULE__, __func__, __LINE__, ##arg)) : (0))
147 * Simplified macro to send a warning log message using the current LOG_TAG.
150 #define LOGW(format, arg...) \
151 (LOG_ON() ? (LOG(LOG_WARN, LOG_TAG, "%s:%s(%d)>"format, __MODULE__, __func__, __LINE__, ##arg)) : (0))
154 * Simplified macro to send a conditional verbose log message using the current LOG_TAG.
157 #define LOGW_IF(cond, ...) \
158 (((CONDITION(cond)) && (LOG_ON())) ? \
159 (LOG(LOG_WARN, LOG_TAG, "%s:%s(%d)>"format, __MODULE__, __func__, __LINE__, ##arg)) : (0))
163 * Simplified macro to send an error log message using the current LOG_TAG.
166 #define LOGE(format, arg...) \
167 (LOG_ON() ? (LOG(LOG_ERROR, LOG_TAG, "%s:%s(%d)>"format, __MODULE__, __func__, __LINE__, ##arg)) : (0))
170 * Simplified macro to send a conditional verbose log message using the current LOG_TAG.
173 #define LOGE_IF(cond, ...) \
174 (((CONDITION(cond)) && (LOG_ON())) ? \
175 (LOG(LOG_ERROR, LOG_TAG, "%s:%s(%d)>"format, __MODULE__, __func__, __LINE__, ##arg)) : (0))
178 * Simplified macro to send an error log message using the current LOG_TAG.
181 #define LOGF(format, arg...) \
182 (LOG_ON() ? (LOG(LOG_FATAL, LOG_TAG, "%s:%s(%d)>"format, __MODULE__, __func__, __LINE__, ##arg)) : (0))
185 * Simplified macro to send a conditional verbose log message using the current LOG_TAG.
188 #define LOGF_IF(cond, ...) \
189 (((CONDITION(cond)) && (LOG_ON())) ? \
190 (LOG(LOG_FATAL, LOG_TAG, "%s:%s(%d)>"format, __MODULE__, __func__, __LINE__, ##arg)) : (0))
193 // ---------------------------------------------------------------------
195 * Simplified radio macro to send a verbose log message using the current LOG_TAG.
199 #define RLOGV(...) (0)
201 #define RLOGV(format, arg...) \
202 (LOG_ON() ? (RLOG(LOG_VERBOSE, LOG_TAG, "%s:%s(%d)>"format, __MODULE__, __func__, __LINE__, ##arg)) : (0))
206 * Simplified radio macro to send a conditional verbose log message using the current LOG_TAG.
210 #define RLOGV_IF(cond, ...) (0)
212 #define RLOGV_IF(cond, ...) \
213 (((CONDITION(cond)) && (LOG_ON())) ? \
214 (RLOG(LOG_VERBOSE, LOG_TAG, "%s:%s(%d)>"format, __MODULE__, __func__, __LINE__, ##arg)) : (0))
219 * Simplified radio macro to send a debug log message using the current LOG_TAG.
222 #define RLOGD(format, arg...) \
223 (LOG_ON() ? (RLOG(LOG_DEBUG, LOG_TAG, "%s:%s(%d)>"format, __MODULE__, __func__, __LINE__, ##arg)) : (0))
226 * Simplified radio macro to send a conditional verbose log message using the current LOG_TAG.
229 #define RLOGD_IF(cond, ...) \
230 (((CONDITION(cond)) && (LOG_ON())) ? \
231 (RLOG(LOG_DEBUG, LOG_TAG, "%s:%s(%d)>"format, __MODULE__, __func__, __LINE__, ##arg)) : (0))
235 * Simplified radio macro to send an info log message using the current LOG_TAG.
238 #define RLOGI(format, arg...) \
239 (LOG_ON() ? (RLOG(LOG_INFO, LOG_TAG, "%s:%s(%d)>"format, __MODULE__, __func__, __LINE__, ##arg)) : (0))
242 * Simplified radio macro to send a conditional verbose log message using the current LOG_TAG.
245 #define RLOGI_IF(cond, ...) \
246 (((CONDITION(cond)) && (LOG_ON())) ? \
247 (RLOG(LOG_INFO, LOG_TAG, "%s:%s(%d)>"format, __MODULE__, __func__, __LINE__, ##arg)) : (0))
251 * Simplified radio macro to send a warning log message using the current LOG_TAG.
254 #define RLOGW(format, arg...) \
255 (LOG_ON() ? (RLOG(LOG_WARN, LOG_TAG, "%s:%s(%d)>"format, __MODULE__, __func__, __LINE__, ##arg)) : (0))
258 * Simplified radio macro to send a conditional verbose log message using the current LOG_TAG.
261 #define RLOGW_IF(cond, ...) \
262 (((CONDITION(cond)) && (LOG_ON())) ? \
263 (RLOG(LOG_WARN, LOG_TAG, "%s:%s(%d)>"format, __MODULE__, __func__, __LINE__, ##arg)) : (0))
267 * Simplified radio macro to send an error log message using the current LOG_TAG.
270 #define RLOGE(format, arg...) \
271 (LOG_ON() ? (RLOG(LOG_ERROR, LOG_TAG, "%s:%s(%d)>"format, __MODULE__, __func__, __LINE__, ##arg)) : (0))
274 * Simplified radio macro to send a conditional verbose log message using the current LOG_TAG.
277 #define RLOGE_IF(cond, ...) \
278 (((CONDITION(cond)) && (LOG_ON())) ? \
279 (RLOG(LOG_ERROR, LOG_TAG, "%s:%s(%d)>"format, __MODULE__, __func__, __LINE__, ##arg)) : (0))
282 * Simplified radio macro to send an error log message using the current LOG_TAG.
285 #define RLOGF(format, arg...) \
286 (LOG_ON() ? (RLOG(LOG_FATAL, LOG_TAG, "%s:%s(%d)>"format, __MODULE__, __func__, __LINE__, ##arg)) : (0))
289 * Simplified radio macro to send a conditional verbose log message using the current LOG_TAG.
292 #define RLOGF_IF(cond, ...) \
293 (((CONDITION(cond)) && (LOG_ON())) ? \
294 (RLOG(LOG_FATAL, LOG_TAG, "%s:%s(%d)>"format, __MODULE__, __func__, __LINE__, ##arg)) : (0))
298 // ---------------------------------------------------------------------
300 * Simplified system macro to send a verbose log message using the current LOG_TAG.
304 #define SLOGV(...) (0)
306 #define SLOGV(format, arg...) \
307 (LOG_ON() ? (SLOG(LOG_VERBOSE, LOG_TAG, "%s:%s(%d)>"format, __MODULE__, __func__, __LINE__, ##arg)) : (0))
311 * Simplified macro to send a conditional verbose log message using the current LOG_TAG.
315 #define SLOGV_IF(cond, ...) (0)
317 #define SLOGV_IF(cond, ...) \
318 (((CONDITION(cond)) && (LOG_ON())) ? \
319 (SLOG(LOG_VERBOSE, LOG_TAG, "%s:%s(%d)>"format, __MODULE__, __func__, __LINE__, ##arg)) : (0))
324 * Simplified system macro to send a debug log message using the current LOG_TAG.
327 #define SLOGD(format, arg...) \
328 (LOG_ON() ? (SLOG(LOG_DEBUG, LOG_TAG, "%s:%s(%d)>"format, __MODULE__, __func__, __LINE__, ##arg)) : (0))
331 * Simplified system macro to send a conditional verbose log message using the current LOG_TAG.
334 #define SLOGD_IF(cond, ...) \
335 (((CONDITION(cond)) && (LOG_ON())) ? \
336 (SLOG(LOG_DEBUG, LOG_TAG, "%s:%s(%d)>"format, __MODULE__, __func__, __LINE__, ##arg)) : (0))
340 * Simplified system macro to send an info log message using the current LOG_TAG.
343 #define SLOGI(format, arg...) \
344 (LOG_ON() ? (SLOG(LOG_INFO, LOG_TAG, "%s:%s(%d)>"format, __MODULE__, __func__, __LINE__, ##arg)) : (0))
347 * Simplified system macro to send a conditional verbose log message using the current LOG_TAG.
350 #define SLOGI_IF(cond, ...) \
351 (((CONDITION(cond)) && (LOG_ON())) ? \
352 (SLOG(LOG_INFO, LOG_TAG, "%s:%s(%d)>"format, __MODULE__, __func__, __LINE__, ##arg)) : (0))
356 * Simplified system macro to send a warning log message using the current LOG_TAG.
359 #define SLOGW(format, arg...) \
360 (LOG_ON() ? (SLOG(LOG_WARN, LOG_TAG, "%s:%s(%d)>"format, __MODULE__, __func__, __LINE__, ##arg)) : (0))
363 * Simplified system macro to send a conditional verbose log message using the current LOG_TAG.
366 #define SLOGW_IF(cond, ...) \
367 (((CONDITION(cond)) && (LOG_ON())) ? \
368 (SLOG(LOG_WARN, LOG_TAG, "%s:%s(%d)>"format, __MODULE__, __func__, __LINE__, ##arg)) : (0))
372 * Simplified system macro to send an error log message using the current LOG_TAG.
375 #define SLOGE(format, arg...) \
376 (LOG_ON() ? (SLOG(LOG_ERROR, LOG_TAG, "%s:%s(%d)>"format, __MODULE__, __func__, __LINE__, ##arg)) : (0))
379 * Simplified system macro to send a conditional verbose log message using the current LOG_TAG.
382 #define SLOGE_IF(cond, ...) \
383 (((CONDITION(cond)) && (LOG_ON())) ? \
384 (SLOG(LOG_ERROR, LOG_TAG, "%s:%s(%d)>"format, __MODULE__, __func__, __LINE__, ##arg)) : (0))
387 * Simplified system macro to send an error log message using the current LOG_TAG.
390 #define SLOGF(format, arg...) \
391 (LOG_ON() ? (SLOG(LOG_FATAL, LOG_TAG, "%s:%s(%d)>"format, __MODULE__, __func__, __LINE__, ##arg)) : (0))
394 * Simplified system macro to send a conditional verbose log message using the current LOG_TAG.
397 #define SLOGF_IF(cond, ...) \
398 (((CONDITION(cond)) && (LOG_ON())) ? \
399 (SLOG(LOG_FATAL, LOG_TAG, "%s:%s(%d)>"format, __MODULE__, __func__, __LINE__, ##arg)) : (0))
402 // ---------------------------------------------------------------------
405 * Simplified macro to send a verbose log message using the current LOG_TAG.
409 #define ALOGV(...) (0)
411 #define ALOGV(...) (ALOG(LOG_VERBOSE, LOG_TAG, __VA_ARGS__))
415 * Simplified macro to send a debug log message using the current LOG_TAG.
418 #define ALOGD(...) (ALOG(LOG_DEBUG, LOG_TAG, __VA_ARGS__))
421 * Simplified macro to send an info log message using the current LOG_TAG.
424 #define ALOGI(...) (ALOG(LOG_INFO, LOG_TAG, __VA_ARGS__))
427 * Simplified macro to send a warning log message using the current LOG_TAG.
430 #define ALOGW(...) (ALOG(LOG_WARN, LOG_TAG, __VA_ARGS__))
433 * Simplified macro to send an error log message using the current LOG_TAG.
436 #define ALOGE(...) (ALOG(LOG_ERROR, LOG_TAG, __VA_ARGS__))
439 // ---------------------------------------------------------------------
441 * Basic log message macro that allows you to specify a priority and a tag
444 * LOG(DLOG_WARN, NULL, "Failed with error %d", errno);
446 * The second argument may be NULL or "" to indicate the "global" tag.
448 * Future work : we want to put filename and line number automatically only when debug build mode
451 #define LOG(priority, tag, ...) \
452 print_log(D##priority, tag, __VA_ARGS__)
456 * Log macro that allows you to pass in a varargs ("args" is a va_list).
459 #define LOG_VA(priority, tag, fmt, args) \
460 vprint_log(D##priority, tag, fmt, args)
464 #define ALOG(priority, tag, ...) \
465 print_apps_log(D##priority, tag, __VA_ARGS__)
468 * Log macro that allows you to pass in a varargs ("args" is a va_list).
471 #define ALOG_VA(priority, tag, fmt, args) \
472 vprint_apps_log(D##priority, tag, fmt, args)
476 * Basic radio log macro that allows you to specify a priority and a tag.
479 #define RLOG(priority, tag, ...) \
480 print_radio_log(D##priority, tag, __VA_ARGS__)
483 * Radio log macro that allows you to pass in a varargs ("args" is a va_list).
486 #define RLOG_VA(priority, tag, fmt, args) \
487 vprint_radio_log(D##priority, tag, fmt, args)
491 * Basic system log macro that allows you to specify a priority and a tag.
494 #define SLOG(priority, tag, ...) \
495 print_system_log(D##priority, tag, __VA_ARGS__)
499 * System log macro that allows you to pass in a varargs ("args" is a va_list).
502 #define SLOG_VA(priority, tag, fmt, args) \
503 vprint_system_log(D##priority, tag, fmt, args)
508 * ===========================================================================
510 * The stuff in the rest of this file should not be used directly.
513 #define print_apps_log(prio, tag, fmt...) \
514 __dlog_print(LOG_ID_APPS, prio, tag, fmt)
516 #define vprint_apps_log(prio, tag, fmt...) \
517 __dlog_vprint(LOG_ID_APPS, prio, tag, fmt)
519 #define print_log(prio, tag, fmt...) \
520 __dlog_print(LOG_ID_MAIN, prio, tag, fmt)
522 #define vprint_log(prio, tag, fmt...) \
523 __dlog_vprint(LOG_ID_MAIN, prio, tag, fmt)
525 #define print_radio_log(prio, tag, fmt...)\
526 __dlog_print(LOG_ID_RADIO, prio, tag, fmt)
528 #define vprint_radio_log(prio, tag, fmt...) \
529 __dlog_vprint(LOG_ID_RADIO, prio, tag, fmt)
531 #define print_system_log(prio, tag, fmt...)\
532 __dlog_print(LOG_ID_SYSTEM, prio, tag, fmt)
534 #define vprint_system_log(prio, tag, fmt...) \
535 __dlog_vprint(LOG_ID_SYSTEM, prio, tag, fmt)
538 * @brief send log. must specify log_id ,priority, tag and format string.
542 * @remarks you must not use this API directly. use macros instead.
543 * @param[in] log_id log device id
544 * @param[in] prio priority
546 * @param[in] fmt format string
547 * @return Operation result
548 * @retval 0>= Success
551 // you have to use LOG(), SLOG(), RLOG() family not to use __dlog_print() directly
552 // so below example is just for passing Documentation Verification !!!
553 #define LOG_TAG USR_TAG
555 __dlog_print(LOG_ID_MAIN, DLOG_INFO, USR_TAG, "you must not use this API directly");
558 int __dlog_print(log_id_t log_id, int prio, const char *tag, const char *fmt, ...);
561 * @brief send log with va_list. must specify log_id ,priority, tag and format string.
565 * @remarks you must not use this API directly. use macros instead.
566 * @param[in] log_id log device id
567 * @param[in] prio priority
569 * @param[in] fmt format string
570 * @param[in] ap va_list
571 * @return Operation result
572 * @retval 0>= Success
575 // you have to use LOG_VA(), SLOG_VA(), RLOG_VA() family not to use __dlog_print() directly
576 // so below example is just for passing Documentation Verification !!!
577 #define LOG_TAG USR_TAG
579 __dlog_vprint(LOG_ID_MAIN, DLOG_INFO, USR_TAG, "you must not use this API directly", ap);
582 int __dlog_vprint(log_id_t log_id, int prio, const char *tag, const char *fmt, va_list ap);
583 int _get_logging_on();
587 #endif /* __cplusplus */