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.
87 #define CONDITION(cond) (__builtin_expect((cond)!=0, 0))
89 // ---------------------------------------------------------------------
92 * Simplified macro to send a verbose log message using the current LOG_TAG.
96 #define LOGV(...) ((void)0)
98 #define LOGV(...) ((void)LOG(LOG_VERBOSE, LOG_TAG, __VA_ARGS__))
104 * Simplified macro to send a conditional verbose log message using the current LOG_TAG.
108 #define LOGV_IF(cond, ...) ((void)0)
110 #define LOGV_IF(cond, ...) \
111 ( (CONDITION(cond)) \
112 ? ((void)LOG(LOG_VERBOSE, LOG_TAG, __VA_ARGS__)) \
118 * Simplified macro to send a debug log message using the current LOG_TAG.
121 #define LOGD(...) ((void)LOG(LOG_DEBUG, LOG_TAG, __VA_ARGS__))
125 * Simplified macro to send a conditional debug log message using the current LOG_TAG.
128 #define LOGD_IF(cond, ...) \
129 ( (CONDITION(cond)) \
130 ? ((void)LOG(LOG_DEBUG, LOG_TAG, __VA_ARGS__)) \
135 * Simplified macro to send an info log message using the current LOG_TAG.
138 #define LOGI(...) ((void)LOG(LOG_INFO, LOG_TAG, __VA_ARGS__))
142 * Simplified macro to send a conditional info log message using the current LOG_TAG.
145 #define LOGI_IF(cond, ...) \
146 ( (CONDITION(cond)) \
147 ? ((void)LOG(LOG_INFO, LOG_TAG, __VA_ARGS__)) \
152 * Simplified macro to send a warning log message using the current LOG_TAG.
155 #define LOGW(...) ((void)LOG(LOG_WARN, LOG_TAG, __VA_ARGS__))
159 * Simplified macro to send a conditional warning log message using the current LOG_TAG.
162 #define LOGW_IF(cond, ...) \
163 ( (CONDITION(cond)) \
164 ? ((void)LOG(LOG_WARN, LOG_TAG, __VA_ARGS__)) \
169 * Simplified macro to send an error log message using the current LOG_TAG.
172 #define LOGE(...) ((void)LOG(LOG_ERROR, LOG_TAG, __VA_ARGS__))
176 * Simplified macro to send a conditional error log message using the current LOG_TAG.
179 #define LOGE_IF(cond, ...) \
180 ( (CONDITION(cond)) \
181 ? ((void)LOG(LOG_ERROR, LOG_TAG, __VA_ARGS__)) \
185 // ---------------------------------------------------------------------
188 * Simplified macro to send a verbose radio log message using the current LOG_TAG.
192 #define RLOGV(...) ((void)0)
194 #define RLOGV(...) ((void)RLOG(LOG_VERBOSE, LOG_TAG, __VA_ARGS__))
199 * Simplified macro to send a conditional verbose radio log message using the current LOG_TAG.
203 #define RLOGV_IF(cond, ...) ((void)0)
205 #define RLOGV_IF(cond, ...) \
206 ( (CONDITION(cond)) \
207 ? ((void)RLOG(LOG_VERBOSE, LOG_TAG, __VA_ARGS__)) \
213 * Simplified macro to send a debug radio log message using the current LOG_TAG.
216 #define RLOGD(...) ((void)RLOG(LOG_DEBUG, LOG_TAG, __VA_ARGS__))
220 * Simplified macro to send a conditional debug radio log message using the current LOG_TAG.
223 #define RLOGD_IF(cond, ...) \
224 ( (CONDITION(cond)) \
225 ? ((void)RLOG(LOG_DEBUG, LOG_TAG, __VA_ARGS__)) \
230 * Simplified macro to send an info radio log message using the current LOG_TAG.
233 #define RLOGI(...) ((void)RLOG(LOG_INFO, LOG_TAG, __VA_ARGS__))
237 * Simplified macro to send a conditional info radio log message using the current LOG_TAG.
240 #define RLOGI_IF(cond, ...) \
241 ( (CONDITION(cond)) \
242 ? ((void)RLOG(LOG_INFO, LOG_TAG, __VA_ARGS__)) \
247 * Simplified macro to send a warning radio log message using the current LOG_TAG.
250 #define RLOGW(...) ((void)RLOG(LOG_WARN, LOG_TAG, __VA_ARGS__))
254 * Simplified macro to send a conditional warning radio log message using the current LOG_TAG.
257 #define RLOGW_IF(cond, ...) \
258 ( (CONDITION(cond)) \
259 ? ((void)RLOG(LOG_WARN, LOG_TAG, __VA_ARGS__)) \
264 * Simplified macro to send an error radio log message using the current LOG_TAG.
267 #define RLOGE(...) ((void)RLOG(LOG_ERROR, LOG_TAG, __VA_ARGS__))
271 * Simplified macro to send a conditional error radio log message using the current LOG_TAG.
274 #define RLOGE_IF(cond, ...) \
275 ( (CONDITION(cond)) \
276 ? ((void)RLOG(LOG_ERROR, LOG_TAG, __VA_ARGS__)) \
280 // ---------------------------------------------------------------------
283 * Simplified macro to send a verbose system log message using the current LOG_TAG.
287 #define SLOGV(...) ((void)0)
289 #define SLOGV(...) ((void)SLOG(LOG_VERBOSE, LOG_TAG, __VA_ARGS__))
294 * Simplified macro to send a conditional verbose system log message using the current LOG_TAG.
298 #define SLOGV_IF(cond, ...) ((void)0)
300 #define SLOGV_IF(cond, ...) \
301 ( (CONDITION(cond)) \
302 ? ((void)SLOG(LOG_VERBOSE, LOG_TAG, __VA_ARGS__)) \
308 * Simplified macro to send a debug system log message using the current LOG_TAG.
311 #define SLOGD(...) ((void)SLOG(LOG_DEBUG, LOG_TAG, __VA_ARGS__))
315 * Simplified macro to send a conditional debug system log message using the current LOG_TAG.
318 #define SLOGD_IF(cond, ...) \
319 ( (CONDITION(cond)) \
320 ? ((void)SLOG(LOG_DEBUG, LOG_TAG, __VA_ARGS__)) \
325 * Simplified macro to send an info system log message using the current LOG_TAG.
328 #define SLOGI(...) ((void)SLOG(LOG_INFO, LOG_TAG, __VA_ARGS__))
332 * Simplified macro to send a conditional info system log message using the current LOG_TAG.
335 #define SLOGI_IF(cond, ...) \
336 ( (CONDITION(cond)) \
337 ? ((void)SLOG(LOG_INFO, LOG_TAG, __VA_ARGS__)) \
342 * Simplified macro to send a warning system log message using the current LOG_TAG.
345 #define SLOGW(...) ((void)SLOG(LOG_WARN, LOG_TAG, __VA_ARGS__))
349 * Simplified macro to send a conditional warning system log message using the current LOG_TAG.
352 #define SLOGW_IF(cond, ...) \
353 ( (CONDITION(cond)) \
354 ? ((void)SLOG(LOG_WARN, LOG_TAG, __VA_ARGS__)) \
359 * Simplified macro to send an error system log message using the current LOG_TAG.
362 #define SLOGE(...) ((void)SLOG(LOG_ERROR, LOG_TAG, __VA_ARGS__))
366 * Simplified macro to send a conditional error system log message using the current LOG_TAG.
369 #define SLOGE_IF(cond, ...) \
370 ( (CONDITION(cond)) \
371 ? ((void)SLOG(LOG_ERROR, LOG_TAG, __VA_ARGS__)) \
375 // TODO : support fatal log
377 // ---------------------------------------------------------------------
380 * Basic log message macro that allows you to specify a priority and a tag
383 * LOG(DLOG_WARN, NULL, "Failed with error %d", errno);
385 * The second argument may be NULL or "" to indicate the "global" tag.
387 * Future work : we want to put filename and line number automatically only when debug build mode
390 #define LOG(priority, tag, ...) \
391 print_log(D##priority, tag, __VA_ARGS__)
395 * Log macro that allows you to pass in a varargs ("args" is a va_list).
398 #define LOG_VA(priority, tag, fmt, args) \
399 vprint_log(D##priority, tag, fmt, args)
403 * Basic radio log macro that allows you to specify a priority and a tag.
406 #define RLOG(priority, tag, ...) \
407 print_radio_log(D##priority, tag, __VA_ARGS__)
411 * Radio log macro that allows you to pass in a varargs ("args" is a va_list).
414 #define RLOG_VA(priority, tag, fmt, args) \
415 vprint_radio_log(D##priority, tag, fmt, args)
419 * Basic system log macro that allows you to specify a priority and a tag.
422 #define SLOG(priority, tag, ...) \
423 print_system_log(D##priority, tag, __VA_ARGS__)
427 * System log macro that allows you to pass in a varargs ("args" is a va_list).
430 #define SLOG_VA(priority, tag, fmt, args) \
431 vprint_system_log(D##priority, tag, fmt, args)
436 * ===========================================================================
438 * The stuff in the rest of this file should not be used directly.
441 #define print_log(prio, tag, fmt...) \
442 __dlog_print(LOG_ID_MAIN, prio, tag, fmt)
444 #define vprint_log(prio, tag, fmt...) \
445 __dlog_vprint(LOG_ID_MAIN, prio, tag, fmt)
447 #define print_radio_log(prio, tag, fmt...)\
448 __dlog_print(LOG_ID_RADIO, prio, tag, fmt)
450 #define vprint_radio_log(prio, tag, fmt...) \
451 __dlog_vprint(LOG_ID_RADIO, prio, tag, fmt)
453 #define print_system_log(prio, tag, fmt...)\
454 __dlog_print(LOG_ID_SYSTEM, prio, tag, fmt)
456 #define vprint_system_log(prio, tag, fmt...) \
457 __dlog_vprint(LOG_ID_SYSTEM, prio, tag, fmt)
460 * @brief send log. must specify log_id ,priority, tag and format string.
464 * @remarks you must not use this API directly. use macros instead.
465 * @param[in] log_id log device id
466 * @param[in] prio priority
468 * @param[in] fmt format string
469 * @return Operation result
470 * @retval 0>= Success
473 // you have to use LOG(), SLOG(), RLOG() family not to use __dlog_print() directly
474 // so below example is just for passing Documentation Verification !!!
475 #define LOG_TAG USR_TAG
477 __dlog_print(LOG_ID_MAIN, DLOG_INFO, USR_TAG, "you must not use this API directly");
480 int __dlog_print(log_id_t log_id, int prio, const char *tag, const char *fmt, ...);
483 * @brief send log with va_list. must specify log_id ,priority, tag and format string.
487 * @remarks you must not use this API directly. use macros instead.
488 * @param[in] log_id log device id
489 * @param[in] prio priority
491 * @param[in] fmt format string
492 * @param[in] ap va_list
493 * @return Operation result
494 * @retval 0>= Success
497 // you have to use LOG_VA(), SLOG_VA(), RLOG_VA() family not to use __dlog_print() directly
498 // so below example is just for passing Documentation Verification !!!
499 #define LOG_TAG USR_TAG
501 __dlog_vprint(LOG_ID_MAIN, DLOG_INFO, USR_TAG, "you must not use this API directly", ap);
504 int __dlog_vprint(log_id_t log_id, int prio, const char *tag, const char *fmt, va_list ap);
508 #endif /* __cplusplus */