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
37 #endif /* __cplusplus */
40 * Normally we strip LOGV (VERBOSE messages) from release builds.
51 * This is the local tag used for the following simplified
52 * logging macros. You can change this preprocessor definition
53 * before using the other macros to change the tag.
59 #define LOG_ON() _get_logging_on()
62 #define __MODULE__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__)
65 * log priority values, in ascending priority order.
87 #define CONDITION(cond) (__builtin_expect((cond) != 0, 0))
89 // ---------------------------------------------------------------------
91 * Simplified macro to send a verbose log message using the current LOG_TAG.
95 #define LOGV(...) ((void)0)
97 #define LOGV(format, arg...) \
98 (LOG_ON() ? (LOG(LOG_VERBOSE, LOG_TAG, "%s:%s(%d)>"format, __MODULE__, __func__, __LINE__, ##arg)) : ((void)0))
102 * Simplified macro to send a conditional verbose log message using the current LOG_TAG.
106 #define LOGV_IF(cond, ...) ((void)0)
108 #define LOGV_IF(cond, ...) \
109 (((CONDITION(cond)) && (LOG_ON())) ? \
110 (LOG(LOG_VERBOSE, LOG_TAG, "%s:%s(%d)>"format, __MODULE__, __func__, __LINE__, ##arg)) : ((void)0))
114 * Simplified macro to send a debug log message using the current LOG_TAG.
117 #define LOGD(format, arg...) \
118 (LOG_ON() ? (LOG(LOG_DEBUG, LOG_TAG, "%s:%s(%d)>"format, __MODULE__, __func__, __LINE__, ##arg)) : ((void)0))
121 * Simplified macro to send a conditional verbose log message using the current LOG_TAG.
124 #define LOGD_IF(cond, ...) \
125 (((CONDITION(cond)) && (LOG_ON())) ? \
126 (LOG(LOG_DEBUG, LOG_TAG, "%s:%s(%d)>"format, __MODULE__, __func__, __LINE__, ##arg)) : ((void)0))
130 * Simplified macro to send an info log message using the current LOG_TAG.
133 #define LOGI(format, arg...) \
134 (LOG_ON() ? (LOG(LOG_INFO, LOG_TAG, "%s:%s(%d)>"format, __MODULE__, __func__, __LINE__, ##arg)) : ((void)0))
137 * Simplified macro to send a conditional verbose log message using the current LOG_TAG.
140 #define LOGI_IF(cond, ...) \
141 (((CONDITION(cond)) && (LOG_ON())) ? \
142 (LOG(LOG_INFO, LOG_TAG, "%s:%s(%d)>"format, __MODULE__, __func__, __LINE__, ##arg)) : ((void)0))
146 * Simplified macro to send a warning log message using the current LOG_TAG.
149 #define LOGW(format, arg...) \
150 (LOG_ON() ? (LOG(LOG_WARN, LOG_TAG, "%s:%s(%d)>"format, __MODULE__, __func__, __LINE__, ##arg)) : ((void)0))
153 * Simplified macro to send a conditional verbose log message using the current LOG_TAG.
156 #define LOGW_IF(cond, ...) \
157 (((CONDITION(cond)) && (LOG_ON())) ? \
158 (LOG(LOG_WARN, LOG_TAG, "%s:%s(%d)>"format, __MODULE__, __func__, __LINE__, ##arg)) : ((void)0))
162 * Simplified macro to send an error log message using the current LOG_TAG.
165 #define LOGE(format, arg...) \
166 (LOG_ON() ? (LOG(LOG_ERROR, LOG_TAG, "%s:%s(%d)>"format, __MODULE__, __func__, __LINE__, ##arg)) : ((void)0))
169 * Simplified macro to send a conditional verbose log message using the current LOG_TAG.
172 #define LOGE_IF(cond, ...) \
173 (((CONDITION(cond)) && (LOG_ON())) ? \
174 (LOG(LOG_ERROR, LOG_TAG, "%s:%s(%d)>"format, __MODULE__, __func__, __LINE__, ##arg)) : ((void)0))
177 * Simplified macro to send an error log message using the current LOG_TAG.
180 #define LOGF(format, arg...) \
181 (LOG_ON() ? (LOG(LOG_FATAL, LOG_TAG, "%s:%s(%d)>"format, __MODULE__, __func__, __LINE__, ##arg)) : ((void)0))
184 * Simplified macro to send a conditional verbose log message using the current LOG_TAG.
187 #define LOGF_IF(cond, ...) \
188 (((CONDITION(cond)) && (LOG_ON())) ? \
189 (LOG(LOG_FATAL, LOG_TAG, "%s:%s(%d)>"format, __MODULE__, __func__, __LINE__, ##arg)) : ((void)0))
192 // ---------------------------------------------------------------------
194 * Simplified radio macro to send a verbose log message using the current LOG_TAG.
198 #define RLOGV(...) ((void)0)
200 #define RLOGV(format, arg...) \
201 (LOG_ON() ? (RLOG(LOG_VERBOSE, LOG_TAG, "%s:%s(%d)>"format, __MODULE__, __func__, __LINE__, ##arg)) : ((void)0))
205 * Simplified radio macro to send a conditional verbose log message using the current LOG_TAG.
209 #define RLOGV_IF(cond, ...) ((void)0)
211 #define RLOGV_IF(cond, ...) \
212 (((CONDITION(cond)) && (LOG_ON())) ? \
213 (RLOG(LOG_VERBOSE, LOG_TAG, "%s:%s(%d)>"format, __MODULE__, __func__, __LINE__, ##arg)) : ((void)0))
218 * Simplified radio macro to send a debug log message using the current LOG_TAG.
221 #define RLOGD(format, arg...) \
222 (LOG_ON() ? (RLOG(LOG_DEBUG, LOG_TAG, "%s:%s(%d)>"format, __MODULE__, __func__, __LINE__, ##arg)) : ((void)0))
225 * Simplified radio macro to send a conditional verbose log message using the current LOG_TAG.
228 #define RLOGD_IF(cond, ...) \
229 (((CONDITION(cond)) && (LOG_ON())) ? \
230 (RLOG(LOG_DEBUG, LOG_TAG, "%s:%s(%d)>"format, __MODULE__, __func__, __LINE__, ##arg)) : ((void)0))
234 * Simplified radio macro to send an info log message using the current LOG_TAG.
237 #define RLOGI(format, arg...) \
238 (LOG_ON() ? (RLOG(LOG_INFO, LOG_TAG, "%s:%s(%d)>"format, __MODULE__, __func__, __LINE__, ##arg)) : ((void)0))
241 * Simplified radio macro to send a conditional verbose log message using the current LOG_TAG.
244 #define RLOGI_IF(cond, ...) \
245 (((CONDITION(cond)) && (LOG_ON())) ? \
246 (RLOG(LOG_INFO, LOG_TAG, "%s:%s(%d)>"format, __MODULE__, __func__, __LINE__, ##arg)) : ((void)0))
250 * Simplified radio macro to send a warning log message using the current LOG_TAG.
253 #define RLOGW(format, arg...) \
254 (LOG_ON() ? (RLOG(LOG_WARN, LOG_TAG, "%s:%s(%d)>"format, __MODULE__, __func__, __LINE__, ##arg)) : ((void)0))
257 * Simplified radio macro to send a conditional verbose log message using the current LOG_TAG.
260 #define RLOGW_IF(cond, ...) \
261 (((CONDITION(cond)) && (LOG_ON())) ? \
262 (RLOG(LOG_WARN, LOG_TAG, "%s:%s(%d)>"format, __MODULE__, __func__, __LINE__, ##arg)) : ((void)0))
266 * Simplified radio macro to send an error log message using the current LOG_TAG.
269 #define RLOGE(format, arg...) \
270 (LOG_ON() ? (RLOG(LOG_ERROR, LOG_TAG, "%s:%s(%d)>"format, __MODULE__, __func__, __LINE__, ##arg)) : ((void)0))
273 * Simplified radio macro to send a conditional verbose log message using the current LOG_TAG.
276 #define RLOGE_IF(cond, ...) \
277 (((CONDITION(cond)) && (LOG_ON())) ? \
278 (RLOG(LOG_ERROR, LOG_TAG, "%s:%s(%d)>"format, __MODULE__, __func__, __LINE__, ##arg)) : ((void)0))
281 * Simplified radio macro to send an error log message using the current LOG_TAG.
284 #define RLOGF(format, arg...) \
285 (LOG_ON() ? (RLOG(LOG_FATAL, LOG_TAG, "%s:%s(%d)>"format, __MODULE__, __func__, __LINE__, ##arg)) : ((void)0))
288 * Simplified radio macro to send a conditional verbose log message using the current LOG_TAG.
291 #define RLOGF_IF(cond, ...) \
292 (((CONDITION(cond)) && (LOG_ON())) ? \
293 (RLOG(LOG_FATAL, LOG_TAG, "%s:%s(%d)>"format, __MODULE__, __func__, __LINE__, ##arg)) : ((void)0))
297 // ---------------------------------------------------------------------
299 * Simplified system macro to send a verbose log message using the current LOG_TAG.
303 #define SLOGV(...) ((void)0)
305 #define SLOGV(format, arg...) \
306 (LOG_ON() ? (SLOG(LOG_VERBOSE, LOG_TAG, "%s:%s(%d)>"format, __MODULE__, __func__, __LINE__, ##arg)) : ((void)0))
310 * Simplified macro to send a conditional verbose log message using the current LOG_TAG.
314 #define SLOGV_IF(cond, ...) ((void)0)
316 #define SLOGV_IF(cond, ...) \
317 (((CONDITION(cond)) && (LOG_ON())) ? \
318 (SLOG(LOG_VERBOSE, LOG_TAG, "%s:%s(%d)>"format, __MODULE__, __func__, __LINE__, ##arg)) : ((void)0))
323 * Simplified system macro to send a debug log message using the current LOG_TAG.
326 #define SLOGD(format, arg...) \
327 (LOG_ON() ? (SLOG(LOG_DEBUG, LOG_TAG, "%s:%s(%d)>"format, __MODULE__, __func__, __LINE__, ##arg)) : ((void)0))
330 * Simplified system macro to send a conditional verbose log message using the current LOG_TAG.
333 #define SLOGD_IF(cond, ...) \
334 (((CONDITION(cond)) && (LOG_ON())) ? \
335 (SLOG(LOG_DEBUG, LOG_TAG, "%s:%s(%d)>"format, __MODULE__, __func__, __LINE__, ##arg)) : ((void)0))
339 * Simplified system macro to send an info log message using the current LOG_TAG.
342 #define SLOGI(format, arg...) \
343 (LOG_ON() ? (SLOG(LOG_INFO, LOG_TAG, "%s:%s(%d)>"format, __MODULE__, __func__, __LINE__, ##arg)) : ((void)0))
346 * Simplified system macro to send a conditional verbose log message using the current LOG_TAG.
349 #define SLOGI_IF(cond, ...) \
350 (((CONDITION(cond)) && (LOG_ON())) ? \
351 (SLOG(LOG_INFO, LOG_TAG, "%s:%s(%d)>"format, __MODULE__, __func__, __LINE__, ##arg)) : ((void)0))
355 * Simplified system macro to send a warning log message using the current LOG_TAG.
358 #define SLOGW(format, arg...) \
359 (LOG_ON() ? (SLOG(LOG_WARN, LOG_TAG, "%s:%s(%d)>"format, __MODULE__, __func__, __LINE__, ##arg)) : ((void)0))
362 * Simplified system macro to send a conditional verbose log message using the current LOG_TAG.
365 #define SLOGW_IF(cond, ...) \
366 (((CONDITION(cond)) && (LOG_ON())) ? \
367 (SLOG(LOG_WARN, LOG_TAG, "%s:%s(%d)>"format, __MODULE__, __func__, __LINE__, ##arg)) : ((void)0))
371 * Simplified system macro to send an error log message using the current LOG_TAG.
374 #define SLOGE(format, arg...) \
375 (LOG_ON() ? (SLOG(LOG_ERROR, LOG_TAG, "%s:%s(%d)>"format, __MODULE__, __func__, __LINE__, ##arg)) : ((void)0))
378 * Simplified system macro to send a conditional verbose log message using the current LOG_TAG.
381 #define SLOGE_IF(cond, ...) \
382 (((CONDITION(cond)) && (LOG_ON())) ? \
383 (SLOG(LOG_ERROR, LOG_TAG, "%s:%s(%d)>"format, __MODULE__, __func__, __LINE__, ##arg)) : ((void)0))
386 * Simplified system macro to send an error log message using the current LOG_TAG.
389 #define SLOGF(format, arg...) \
390 (LOG_ON() ? (SLOG(LOG_FATAL, LOG_TAG, "%s:%s(%d)>"format, __MODULE__, __func__, __LINE__, ##arg)) : ((void)0))
393 * Simplified system macro to send a conditional verbose log message using the current LOG_TAG.
396 #define SLOGF_IF(cond, ...) \
397 (((CONDITION(cond)) && (LOG_ON())) ? \
398 (SLOG(LOG_FATAL, LOG_TAG, "%s:%s(%d)>"format, __MODULE__, __func__, __LINE__, ##arg)) : ((void)0))
401 // ---------------------------------------------------------------------
404 * Simplified macro to send a verbose log message using the current LOG_TAG.
408 #define ALOGV(...) ((void)0)
410 #define ALOGV(...) ((void)ALOG(LOG_VERBOSE, LOG_TAG, __VA_ARGS__))
414 * Simplified macro to send a debug log message using the current LOG_TAG.
417 #define ALOGD(...) ((void)ALOG(LOG_DEBUG, LOG_TAG, __VA_ARGS__))
420 * Simplified macro to send an info log message using the current LOG_TAG.
423 #define ALOGI(...) ((void)ALOG(LOG_INFO, LOG_TAG, __VA_ARGS__))
426 * Simplified macro to send a warning log message using the current LOG_TAG.
429 #define ALOGW(...) ((void)ALOG(LOG_WARN, LOG_TAG, __VA_ARGS__))
432 * Simplified macro to send an error log message using the current LOG_TAG.
435 #define ALOGE(...) ((void)ALOG(LOG_ERROR, LOG_TAG, __VA_ARGS__))
438 // ---------------------------------------------------------------------
440 * Basic log message macro that allows you to specify a priority and a tag
443 * LOG(DLOG_WARN, NULL, "Failed with error %d", errno);
445 * The second argument may be NULL or "" to indicate the "global" tag.
447 * Future work : we want to put filename and line number automatically only when debug build mode
450 #define LOG(priority, tag, ...) \
451 print_log(D##priority, tag, __VA_ARGS__)
455 * tizen app log macro that allows you to specify a priority and a tag.
458 #define ALOG(priority, tag, ...) \
459 print_apps_log(D##priority, tag, __VA_ARGS__)
462 * Basic radio log macro that allows you to specify a priority and a tag.
465 #define RLOG(priority, tag, ...) \
466 print_radio_log(D##priority, tag, __VA_ARGS__)
469 * Basic system log macro that allows you to specify a priority and a tag.
472 #define SLOG(priority, tag, ...) \
473 print_system_log(D##priority, tag, __VA_ARGS__)
477 * ===========================================================================
479 * The stuff in the rest of this file should not be used directly.
482 #define print_apps_log(prio, tag, fmt...) \
483 __dlog_print(LOG_ID_APPS, prio, tag, fmt)
485 #define print_log(prio, tag, fmt...) \
486 __dlog_print(LOG_ID_MAIN, prio, tag, fmt)
488 #define print_radio_log(prio, tag, fmt...)\
489 __dlog_print(LOG_ID_RADIO, prio, tag, fmt)
491 #define print_system_log(prio, tag, fmt...)\
492 __dlog_print(LOG_ID_SYSTEM, prio, tag, fmt)
495 * @brief send log. must specify log_id ,priority, tag and format string.
499 * @remarks you must not use this API directly. use macros instead.
500 * @param[in] log_id log device id
501 * @param[in] prio priority
503 * @param[in] fmt format string
504 * @return Operation result
505 * @retval 0>= Success
508 // you have to use LOG(), SLOG(), RLOG() family not to use __dlog_print() directly
509 // so below example is just for passing Documentation Verification !!!
510 #define LOG_TAG USR_TAG
512 __dlog_print(LOG_ID_MAIN, DLOG_INFO, USR_TAG, "you must not use this API directly");
515 int __dlog_print(log_id_t log_id, int prio, const char *tag, const char *fmt, ...);
516 int __dlog_vprint(log_id_t log_id, int prio, const char *tag, const char *fmt, va_list ap);
517 int _get_logging_on();
521 #endif /* __cplusplus */