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 // ---------------------------------------------------------------------
101 #define SECLOG(...) (0)
103 #define SECLOG(format, arg...) \
104 (LOG_ON() ? (SLOG(LOG_WARN, LOG_TAG, "%s: %s(%d) > " format, __MODULE__, __func__, __LINE__, ##arg)) : (0))
108 // ---------------------------------------------------------------------
110 * Simplified macro to send a verbose log message using the current LOG_TAG.
114 #define LOGV(...) (0)
116 #define LOGV(format, arg...) \
117 (LOG_ON() ? (LOG(LOG_VERBOSE, LOG_TAG, "%s: %s(%d) > " format, __MODULE__, __func__, __LINE__, ##arg)) : (0))
121 * Simplified macro to send a conditional verbose log message using the current LOG_TAG.
125 #define LOGV_IF(cond, format, arg...) (0)
127 #define LOGV_IF(cond, format, arg...) \
128 (((CONDITION(cond)) && (LOG_ON())) ? \
129 (LOG(LOG_VERBOSE, LOG_TAG, "%s: %s(%d) > " format, __MODULE__, __func__, __LINE__, ##arg)) : (0))
133 * Simplified macro to send a debug log message using the current LOG_TAG.
136 #define LOGD(format, arg...) \
137 (LOG_ON() ? (LOG(LOG_DEBUG, 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 LOGD_IF(cond, format, arg...) \
144 (((CONDITION(cond)) && (LOG_ON())) ? \
145 (LOG(LOG_DEBUG, LOG_TAG, "%s: %s(%d) > " format, __MODULE__, __func__, __LINE__, ##arg)) : (0))
149 * Simplified macro to send an info log message using the current LOG_TAG.
152 #define LOGI(format, arg...) \
153 (LOG_ON() ? (LOG(LOG_INFO, 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 LOGI_IF(cond, format, arg...) \
160 (((CONDITION(cond)) && (LOG_ON())) ? \
161 (LOG(LOG_INFO, LOG_TAG, "%s: %s(%d) > " format, __MODULE__, __func__, __LINE__, ##arg)) : (0))
165 * Simplified macro to send a warning log message using the current LOG_TAG.
168 #define LOGW(format, arg...) \
169 (LOG_ON() ? (LOG(LOG_WARN, 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 LOGW_IF(cond, format, arg...) \
176 (((CONDITION(cond)) && (LOG_ON())) ? \
177 (LOG(LOG_WARN, LOG_TAG, "%s: %s(%d) > " format, __MODULE__, __func__, __LINE__, ##arg)) : (0))
181 * Simplified macro to send an error log message using the current LOG_TAG.
184 #define LOGE(format, arg...) \
185 (LOG_ON() ? (LOG(LOG_ERROR, LOG_TAG, "%s: %s(%d) > " format, __MODULE__, __func__, __LINE__, ##arg)) : (0))
188 * Simplified macro to send a conditional verbose log message using the current LOG_TAG.
191 #define LOGE_IF(cond, format, arg...) \
192 (((CONDITION(cond)) && (LOG_ON())) ? \
193 (LOG(LOG_ERROR, LOG_TAG, "%s: %s(%d) > " format, __MODULE__, __func__, __LINE__, ##arg)) : (0))
196 * Simplified macro to send an error log message using the current LOG_TAG.
199 #define LOGF(format, arg...) \
200 (LOG_ON() ? (LOG(LOG_FATAL, LOG_TAG, "%s: %s(%d) > " format, __MODULE__, __func__, __LINE__, ##arg)) : (0))
203 * Simplified macro to send a conditional verbose log message using the current LOG_TAG.
206 #define LOGF_IF(cond, format, arg...) \
207 (((CONDITION(cond)) && (LOG_ON())) ? \
208 (LOG(LOG_FATAL, LOG_TAG, "%s: %s(%d) > " format, __MODULE__, __func__, __LINE__, ##arg)) : (0))
211 // ---------------------------------------------------------------------
213 * Simplified radio macro to send a verbose log message using the current LOG_TAG.
217 #define RLOGV(...) (0)
219 #define RLOGV(format, arg...) \
220 (LOG_ON() ? (RLOG(LOG_VERBOSE, LOG_TAG, "%s: %s(%d) > " format, __MODULE__, __func__, __LINE__, ##arg)) : (0))
224 * Simplified radio macro to send a conditional verbose log message using the current LOG_TAG.
228 #define RLOGV_IF(cond, format, arg...) (0)
230 #define RLOGV_IF(cond, format, arg...) \
231 (((CONDITION(cond)) && (LOG_ON())) ? \
232 (RLOG(LOG_VERBOSE, LOG_TAG, "%s: %s(%d) > " format, __MODULE__, __func__, __LINE__, ##arg)) : (0))
237 * Simplified radio macro to send a debug log message using the current LOG_TAG.
240 #define RLOGD(format, arg...) \
241 (LOG_ON() ? (RLOG(LOG_DEBUG, 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 RLOGD_IF(cond, format, arg...) \
248 (((CONDITION(cond)) && (LOG_ON())) ? \
249 (RLOG(LOG_DEBUG, LOG_TAG, "%s: %s(%d) > " format, __MODULE__, __func__, __LINE__, ##arg)) : (0))
253 * Simplified radio macro to send an info log message using the current LOG_TAG.
256 #define RLOGI(format, arg...) \
257 (LOG_ON() ? (RLOG(LOG_INFO, 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 RLOGI_IF(cond, format, arg...) \
264 (((CONDITION(cond)) && (LOG_ON())) ? \
265 (RLOG(LOG_INFO, LOG_TAG, "%s: %s(%d) > " format, __MODULE__, __func__, __LINE__, ##arg)) : (0))
269 * Simplified radio macro to send a warning log message using the current LOG_TAG.
272 #define RLOGW(format, arg...) \
273 (LOG_ON() ? (RLOG(LOG_WARN, 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 RLOGW_IF(cond, format, arg...) \
280 (((CONDITION(cond)) && (LOG_ON())) ? \
281 (RLOG(LOG_WARN, LOG_TAG, "%s: %s(%d) > " format, __MODULE__, __func__, __LINE__, ##arg)) : (0))
285 * Simplified radio macro to send an error log message using the current LOG_TAG.
288 #define RLOGE(format, arg...) \
289 (LOG_ON() ? (RLOG(LOG_ERROR, LOG_TAG, "%s: %s(%d) > " format, __MODULE__, __func__, __LINE__, ##arg)) : (0))
292 * Simplified radio macro to send a conditional verbose log message using the current LOG_TAG.
295 #define RLOGE_IF(cond, format, arg...) \
296 (((CONDITION(cond)) && (LOG_ON())) ? \
297 (RLOG(LOG_ERROR, LOG_TAG, "%s: %s(%d) > " format, __MODULE__, __func__, __LINE__, ##arg)) : (0))
300 * Simplified radio macro to send an error log message using the current LOG_TAG.
303 #define RLOGF(format, arg...) \
304 (LOG_ON() ? (RLOG(LOG_FATAL, LOG_TAG, "%s: %s(%d) > " format, __MODULE__, __func__, __LINE__, ##arg)) : (0))
307 * Simplified radio macro to send a conditional verbose log message using the current LOG_TAG.
310 #define RLOGF_IF(cond, format, arg...) \
311 (((CONDITION(cond)) && (LOG_ON())) ? \
312 (RLOG(LOG_FATAL, LOG_TAG, "%s: %s(%d) > " format, __MODULE__, __func__, __LINE__, ##arg)) : (0))
316 // ---------------------------------------------------------------------
318 * Simplified system macro to send a verbose log message using the current LOG_TAG.
322 #define SLOGV(...) (0)
324 #define SLOGV(format, arg...) \
325 (LOG_ON() ? (SLOG(LOG_VERBOSE, LOG_TAG, "%s: %s(%d) > " format, __MODULE__, __func__, __LINE__, ##arg)) : (0))
329 * Simplified macro to send a conditional verbose log message using the current LOG_TAG.
333 #define SLOGV_IF(cond, format, arg...) (0)
335 #define SLOGV_IF(cond, format, arg...) \
336 (((CONDITION(cond)) && (LOG_ON())) ? \
337 (SLOG(LOG_VERBOSE, LOG_TAG, "%s: %s(%d) > " format, __MODULE__, __func__, __LINE__, ##arg)) : (0))
342 * Simplified system macro to send a debug log message using the current LOG_TAG.
345 #define SLOGD(format, arg...) \
346 (LOG_ON() ? (SLOG(LOG_DEBUG, 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 SLOGD_IF(cond, format, arg...) \
353 (((CONDITION(cond)) && (LOG_ON())) ? \
354 (SLOG(LOG_DEBUG, LOG_TAG, "%s: %s(%d) > " format, __MODULE__, __func__, __LINE__, ##arg)) : (0))
358 * Simplified system macro to send an info log message using the current LOG_TAG.
361 #define SLOGI(format, arg...) \
362 (LOG_ON() ? (SLOG(LOG_INFO, 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 SLOGI_IF(cond, format, arg...) \
369 (((CONDITION(cond)) && (LOG_ON())) ? \
370 (SLOG(LOG_INFO, LOG_TAG, "%s: %s(%d) > " format, __MODULE__, __func__, __LINE__, ##arg)) : (0))
374 * Simplified system macro to send a warning log message using the current LOG_TAG.
377 #define SLOGW(format, arg...) \
378 (LOG_ON() ? (SLOG(LOG_WARN, 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 SLOGW_IF(cond, format, arg...) \
385 (((CONDITION(cond)) && (LOG_ON())) ? \
386 (SLOG(LOG_WARN, LOG_TAG, "%s: %s(%d) > " format, __MODULE__, __func__, __LINE__, ##arg)) : (0))
390 * Simplified system macro to send an error log message using the current LOG_TAG.
393 #define SLOGE(format, arg...) \
394 (LOG_ON() ? (SLOG(LOG_ERROR, LOG_TAG, "%s: %s(%d) > " format, __MODULE__, __func__, __LINE__, ##arg)) : (0))
397 * Simplified system macro to send a conditional verbose log message using the current LOG_TAG.
400 #define SLOGE_IF(cond, format, arg...) \
401 (((CONDITION(cond)) && (LOG_ON())) ? \
402 (SLOG(LOG_ERROR, LOG_TAG, "%s: %s(%d) > " format, __MODULE__, __func__, __LINE__, ##arg)) : (0))
405 * Simplified system macro to send an error log message using the current LOG_TAG.
408 #define SLOGF(format, arg...) \
409 (LOG_ON() ? (SLOG(LOG_FATAL, LOG_TAG, "%s: %s(%d) > " format, __MODULE__, __func__, __LINE__, ##arg)) : (0))
412 * Simplified system macro to send a conditional verbose log message using the current LOG_TAG.
415 #define SLOGF_IF(cond, format, arg...) \
416 (((CONDITION(cond)) && (LOG_ON())) ? \
417 (SLOG(LOG_FATAL, LOG_TAG, "%s: %s(%d) > " format, __MODULE__, __func__, __LINE__, ##arg)) : (0))
420 // ---------------------------------------------------------------------
423 * Simplified macro to send a verbose log message using the current LOG_TAG.
427 #define ALOGV(...) (0)
429 #define ALOGV(...) (ALOG(LOG_VERBOSE, LOG_TAG, __VA_ARGS__))
433 * Simplified macro to send a debug log message using the current LOG_TAG.
436 #define ALOGD(...) (ALOG(LOG_DEBUG, LOG_TAG, __VA_ARGS__))
439 * Simplified macro to send an info log message using the current LOG_TAG.
442 #define ALOGI(...) (ALOG(LOG_INFO, LOG_TAG, __VA_ARGS__))
445 * Simplified macro to send a warning log message using the current LOG_TAG.
448 #define ALOGW(...) (ALOG(LOG_WARN, LOG_TAG, __VA_ARGS__))
451 * Simplified macro to send an error log message using the current LOG_TAG.
454 #define ALOGE(...) (ALOG(LOG_ERROR, LOG_TAG, __VA_ARGS__))
458 // ---------------------------------------------------------------------
460 * Basic log message macro that allows you to specify a priority and a tag
463 * LOG(DLOG_WARN, NULL, "Failed with error %d", errno);
465 * The second argument may be NULL or "" to indicate the "global" tag.
467 * Future work : we want to put filename and line number automatically only when debug build mode
470 #define LOG(priority, tag, ...) \
471 print_log(D##priority, tag, __VA_ARGS__)
475 * Log macro that allows you to pass in a varargs ("args" is a va_list).
478 #define LOG_VA(priority, tag, fmt, args) \
479 vprint_log(D##priority, tag, fmt, args)
483 #define ALOG(priority, tag, ...) \
484 print_apps_log(D##priority, tag, __VA_ARGS__)
487 * Log macro that allows you to pass in a varargs ("args" is a va_list).
490 #define ALOG_VA(priority, tag, fmt, args) \
491 vprint_apps_log(D##priority, tag, fmt, args)
495 * Basic radio log macro that allows you to specify a priority and a tag.
498 #define RLOG(priority, tag, ...) \
499 print_radio_log(D##priority, tag, __VA_ARGS__)
502 * Radio log macro that allows you to pass in a varargs ("args" is a va_list).
505 #define RLOG_VA(priority, tag, fmt, args) \
506 vprint_radio_log(D##priority, tag, fmt, args)
510 * Basic system log macro that allows you to specify a priority and a tag.
513 #define SLOG(priority, tag, ...) \
514 print_system_log(D##priority, tag, __VA_ARGS__)
518 * System log macro that allows you to pass in a varargs ("args" is a va_list).
521 #define SLOG_VA(priority, tag, fmt, args) \
522 vprint_system_log(D##priority, tag, fmt, args)
527 * ===========================================================================
529 * The stuff in the rest of this file should not be used directly.
532 #define print_apps_log(prio, tag, fmt...) \
533 __dlog_print(LOG_ID_APPS, prio, tag, fmt)
535 #define vprint_apps_log(prio, tag, fmt...) \
536 __dlog_vprint(LOG_ID_APPS, prio, tag, fmt)
538 #define print_log(prio, tag, fmt...) \
539 __dlog_print(LOG_ID_MAIN, prio, tag, fmt)
541 #define vprint_log(prio, tag, fmt...) \
542 __dlog_vprint(LOG_ID_MAIN, prio, tag, fmt)
544 #define print_radio_log(prio, tag, fmt...)\
545 __dlog_print(LOG_ID_RADIO, prio, tag, fmt)
547 #define vprint_radio_log(prio, tag, fmt...) \
548 __dlog_vprint(LOG_ID_RADIO, prio, tag, fmt)
550 #define print_system_log(prio, tag, fmt...)\
551 __dlog_print(LOG_ID_SYSTEM, prio, tag, fmt)
553 #define vprint_system_log(prio, tag, fmt...) \
554 __dlog_vprint(LOG_ID_SYSTEM, prio, tag, fmt)
557 * @brief send log. must specify log_id ,priority, tag and format string.
561 * @remarks you must not use this API directly. use macros instead.
562 * @param[in] log_id log device id
563 * @param[in] prio priority
565 * @param[in] fmt format string
566 * @return Operation result
567 * @retval 0>= Success
570 // you have to use LOG(), SLOG(), RLOG() family not to use __dlog_print() directly
571 // so below example is just for passing Documentation Verification !!!
572 #define LOG_TAG USR_TAG
574 __dlog_print(LOG_ID_MAIN, DLOG_INFO, USR_TAG, "you must not use this API directly");
577 int __dlog_print(log_id_t log_id, int prio, const char *tag, const char *fmt, ...);
580 * @brief send log with va_list. must specify log_id ,priority, tag and format string.
584 * @remarks you must not use this API directly. use macros instead.
585 * @param[in] log_id log device id
586 * @param[in] prio priority
588 * @param[in] fmt format string
589 * @param[in] ap va_list
590 * @return Operation result
591 * @retval 0>= Success
594 // you have to use LOG_VA(), SLOG_VA(), RLOG_VA() family not to use __dlog_print() directly
595 // so below example is just for passing Documentation Verification !!!
596 #define LOG_TAG USR_TAG
598 __dlog_vprint(LOG_ID_MAIN, DLOG_INFO, USR_TAG, "you must not use this API directly", ap);
601 int __dlog_vprint(log_id_t log_id, int prio, const char *tag, const char *fmt, va_list ap);
602 int _get_logging_on(void);
606 #endif /* __cplusplus */