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.
20 * @file dlog-internal.h
22 * @brief This file is the header file of interface of dlog.
24 #ifndef _DLOG_INTERNAL_H_
25 #define _DLOG_INTERNAL_H_
27 #include <tizen_error.h>
35 #endif /* __cplusplus */
38 * This is the local tag used for the following simplified
39 * logging macros. You can change this preprocessor definition
40 * before using the other macros to change the tag.
47 #define __MODULE__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__)
50 #ifdef TIZEN_ENGINEER_MODE
51 #ifndef TIZEN_DEBUG_ENABLE
52 #define TIZEN_DEBUG_ENABLE
59 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
69 static inline int __dlog_no_print(const char *fmt __attribute__((unused)), ...) { return 0; }
71 #define CONDITION(cond) (__builtin_expect((cond) != 0, 0))
72 #define NOP(...) ({ do { __dlog_no_print(__VA_ARGS__); } while (0); })
74 // Macro inner work---------------------------------------------------------------
76 #ifdef TIZEN_DEBUG_ENABLE
77 #define LOG_(id, prio, tag, fmt, arg...) \
79 __dlog_print(id, prio, tag, "%s: %s(%d) > " fmt, __MODULE__, __func__, __LINE__, ##arg); \
82 #define LOG_(id, prio, tag, fmt, arg...) \
84 if ((int)prio != DLOG_DEBUG) { \
85 __dlog_print(id, prio, tag, "%s: %s(%d) > " fmt, __MODULE__, __func__, __LINE__, ##arg); \
91 #ifdef TIZEN_DEBUG_ENABLE
92 #define SECURE_LOG_(id, prio, tag, fmt, arg...) \
94 __dlog_print(id, prio, tag, "%s: %s(%d) > [SECURE_LOG] " fmt, __MODULE__, __func__, __LINE__, ##arg); \
97 #define SECURE_LOG_(id, prio, tag, fmt, arg...) NOP(fmt, ##arg)
99 // ---------------------------------------------------------------------
102 * @brief For Secure Log.
103 * @remarks Normally we strip Secure log from release builds.
104 * Please use this macros.
108 * @brief For Application and etc.
109 * @details Simplified macro to send a main log message using the current LOG_TAG.
111 * SECURE_LOGD("app debug %d", num);
112 * SECURE_LOGE("app error %d", num);
114 #define SECURE_LOGD(format, arg...) SECURE_LOG_(LOG_ID_MAIN, DLOG_DEBUG, LOG_TAG, format, ##arg)
115 #define SECURE_LOGI(format, arg...) SECURE_LOG_(LOG_ID_MAIN, DLOG_INFO, LOG_TAG, format, ##arg)
116 #define SECURE_LOGW(format, arg...) SECURE_LOG_(LOG_ID_MAIN, DLOG_WARN, LOG_TAG, format, ##arg)
117 #define SECURE_LOGE(format, arg...) SECURE_LOG_(LOG_ID_MAIN, DLOG_ERROR, LOG_TAG, format, ##arg)
118 #define SECURE_LOGF(format, arg...) SECURE_LOG_(LOG_ID_MAIN, DLOG_FATAL, LOG_TAG, format, ##arg)
121 * @brief For Framework and system etc.
122 * @details Simplified macro to send a system log message using the current LOG_TAG.
124 * SECURE_SLOGD("system debug %d", num);
125 * SECURE_SLOGE("system error %d", num);
127 #define SECURE_SLOGD(format, arg...) SECURE_LOG_(LOG_ID_SYSTEM, DLOG_DEBUG, LOG_TAG, format, ##arg)
128 #define SECURE_SLOGI(format, arg...) SECURE_LOG_(LOG_ID_SYSTEM, DLOG_INFO, LOG_TAG, format, ##arg)
129 #define SECURE_SLOGW(format, arg...) SECURE_LOG_(LOG_ID_SYSTEM, DLOG_WARN, LOG_TAG, format, ##arg)
130 #define SECURE_SLOGE(format, arg...) SECURE_LOG_(LOG_ID_SYSTEM, DLOG_ERROR, LOG_TAG, format, ##arg)
131 #define SECURE_SLOGF(format, arg...) SECURE_LOG_(LOG_ID_SYSTEM, DLOG_FATAL, LOG_TAG, format, ##arg)
134 * @brief For Modem and radio etc.
135 * @details Simplified macro to send a radio log message using the current LOG_TAG.
137 * SECURE_RLOGD("radio debug %d", num);
138 * SECURE_RLOGE("radio error %d", num);
140 #define SECURE_RLOGD(format, arg...) SECURE_LOG_(LOG_ID_RADIO, DLOG_DEBUG, LOG_TAG, format, ##arg)
141 #define SECURE_RLOGI(format, arg...) SECURE_LOG_(LOG_ID_RADIO, DLOG_INFO, LOG_TAG, format, ##arg)
142 #define SECURE_RLOGW(format, arg...) SECURE_LOG_(LOG_ID_RADIO, DLOG_WARN, LOG_TAG, format, ##arg)
143 #define SECURE_RLOGE(format, arg...) SECURE_LOG_(LOG_ID_RADIO, DLOG_ERROR, LOG_TAG, format, ##arg)
144 #define SECURE_RLOGF(format, arg...) SECURE_LOG_(LOG_ID_RADIO, DLOG_FATAL, LOG_TAG, format, ##arg)
147 * @brief For Tizen OSP Application macro.
149 #define SECURE_ALOGD(format, arg...) SECURE_LOG_(LOG_ID_APPS, DLOG_DEBUG, LOG_TAG, format, ##arg)
150 #define SECURE_ALOGI(format, arg...) SECURE_LOG_(LOG_ID_APPS, DLOG_INFO, LOG_TAG, format, ##arg)
151 #define SECURE_ALOGW(format, arg...) SECURE_LOG_(LOG_ID_APPS, DLOG_WARN, LOG_TAG, format, ##arg)
152 #define SECURE_ALOGE(format, arg...) SECURE_LOG_(LOG_ID_APPS, DLOG_ERROR, LOG_TAG, format, ##arg)
153 #define SECURE_ALOGF(format, arg...) SECURE_LOG_(LOG_ID_APPS, DLOG_FATAL, LOG_TAG, format, ##arg)
156 * @details If you want use redefined macro.
157 * You can use this macro.
158 * This macro need priority and tag arguments.
160 #define SECURE_LOG(priority, tag, format, arg...) SECURE_LOG_(LOG_ID_MAIN, D##priority, tag, format, ##arg)
161 #define SECURE_SLOG(priority, tag, format, arg...) SECURE_LOG_(LOG_ID_SYSTEM, D##priority, tag, format, ##arg)
162 #define SECURE_RLOG(priority, tag, format, arg...) SECURE_LOG_(LOG_ID_RADIO, D##priority, tag, format, ##arg)
163 #define SECURE_ALOG(priority, tag, format, arg...) SECURE_LOG_(LOG_ID_APPS, D##priority, tag, format, ##arg)
167 * @brief For Application and etc.
168 * @details Simplified macro to send a main log message using the current LOG_TAG.
170 * LOGD("app debug %d", num);
171 * LOGE("app error %d", num);
173 #ifdef TIZEN_DEBUG_ENABLE
174 #define LOGD(format, arg...) LOG_(LOG_ID_MAIN, DLOG_DEBUG, LOG_TAG, format, ##arg)
176 #define LOGD(format, arg...) NOP(format, ##arg)
178 #define LOGI(format, arg...) LOG_(LOG_ID_MAIN, DLOG_INFO, LOG_TAG, format, ##arg)
179 #define LOGW(format, arg...) LOG_(LOG_ID_MAIN, DLOG_WARN, LOG_TAG, format, ##arg)
180 #define LOGE(format, arg...) LOG_(LOG_ID_MAIN, DLOG_ERROR, LOG_TAG, format, ##arg)
181 #define LOGF(format, arg...) LOG_(LOG_ID_MAIN, DLOG_FATAL, LOG_TAG, format, ##arg)
184 * @brief For Framework and system etc.
185 * @details Simplified macro to send a system log message using the current LOG_TAG.
187 * SLOGD("system debug %d", num);
188 * SLOGE("system error %d", num);
190 #ifdef TIZEN_DEBUG_ENABLE
191 #define SLOGD(format, arg...) LOG_(LOG_ID_SYSTEM, DLOG_DEBUG, LOG_TAG, format, ##arg)
193 #define SLOGD(format, arg...) NOP(format, ##arg)
195 #define SLOGI(format, arg...) LOG_(LOG_ID_SYSTEM, DLOG_INFO, LOG_TAG, format, ##arg)
196 #define SLOGW(format, arg...) LOG_(LOG_ID_SYSTEM, DLOG_WARN, LOG_TAG, format, ##arg)
197 #define SLOGE(format, arg...) LOG_(LOG_ID_SYSTEM, DLOG_ERROR, LOG_TAG, format, ##arg)
198 #define SLOGF(format, arg...) LOG_(LOG_ID_SYSTEM, DLOG_FATAL, LOG_TAG, format, ##arg)
201 * @brief For Modem and radio etc.
202 * @details Simplified macro to send a radio log message using the current LOG_TAG.
204 * RLOGD("radio debug %d", num);
205 * RLOGE("radio error %d", num);
207 #ifdef TIZEN_DEBUG_ENABLE
208 #define RLOGD(format, arg...) LOG_(LOG_ID_RADIO, DLOG_DEBUG, LOG_TAG, format, ##arg)
210 #define RLOGD(format, arg...) NOP(format, ##arg)
212 #define RLOGI(format, arg...) LOG_(LOG_ID_RADIO, DLOG_INFO, LOG_TAG, format, ##arg)
213 #define RLOGW(format, arg...) LOG_(LOG_ID_RADIO, DLOG_WARN, LOG_TAG, format, ##arg)
214 #define RLOGE(format, arg...) LOG_(LOG_ID_RADIO, DLOG_ERROR, LOG_TAG, format, ##arg)
215 #define RLOGF(format, arg...) LOG_(LOG_ID_RADIO, DLOG_FATAL, LOG_TAG, format, ##arg)
218 * @brief For Tizen OSP Application macro.
220 #ifdef TIZEN_DEBUG_ENABLE
221 #define ALOGD(format, arg...) LOG_(LOG_ID_APPS, DLOG_DEBUG, LOG_TAG, format, ##arg)
223 #define ALOGD(format, arg...) NOP(format, ##arg)
225 #define ALOGI(format, arg...) LOG_(LOG_ID_APPS, DLOG_INFO, LOG_TAG, format, ##arg)
226 #define ALOGW(format, arg...) LOG_(LOG_ID_APPS, DLOG_WARN, LOG_TAG, format, ##arg)
227 #define ALOGE(format, arg...) LOG_(LOG_ID_APPS, DLOG_ERROR, LOG_TAG, format, ##arg)
228 #define ALOGF(format, arg...) LOG_(LOG_ID_APPS, DLOG_FATAL, LOG_TAG, format, ##arg)
232 * @brief Basic log message macro
233 * @details This macro allows you to specify a priority and a tag
234 * if you want to use this macro directly, you must add this messages for unity of messages.
235 * (LOG(prio, tag, "%s: %s(%d) > " format, __MODULE__, __func__, __LINE__, ##arg))
238 * #define MYMACRO(prio, tag, format, arg...) \
239 * LOG(prio, tag, format, ##arg)
241 * MYMACRO(LOG_DEBUG, MYTAG, "test mymacro %d", num);
245 #define LOG(priority, tag, format, arg...) LOG_(LOG_ID_MAIN, D##priority, tag, format, ##arg)
247 #define SLOG(priority, tag, format, arg...) LOG_(LOG_ID_SYSTEM, D##priority, tag, format, ##arg)
248 #define RLOG(priority, tag, format, arg...) LOG_(LOG_ID_RADIO, D##priority, tag, format, ##arg)
249 #define ALOG(priority, tag, format, arg...) LOG_(LOG_ID_APPS, D##priority, tag, format, ##arg)
253 #define LOG_VA(priority, tag, fmt, args) \
254 vprint_log(D##priority, tag, fmt, args)
255 #define ALOG_VA(priority, tag, fmt, args) \
256 vprint_apps_log(D##priority, tag, fmt, args)
257 #define RLOG_VA(priority, tag, fmt, args) \
258 vprint_radio_log(D##priority, tag, fmt, args)
259 #define SLOG_VA(priority, tag, fmt, args) \
260 vprint_system_log(D##priority, tag, fmt, args)
261 #define print_apps_log(prio, tag, fmt...) \
262 __dlog_print(LOG_ID_APPS, prio, tag, fmt)
263 #define vprint_apps_log(prio, tag, fmt...) \
264 __dlog_vprint(LOG_ID_APPS, prio, tag, fmt)
265 #define print_log(prio, tag, fmt...) \
266 __dlog_print(LOG_ID_MAIN, prio, tag, fmt)
267 #define vprint_log(prio, tag, fmt...) \
268 __dlog_vprint(LOG_ID_MAIN, prio, tag, fmt)
269 #define print_radio_log(prio, tag, fmt...)\
270 __dlog_print(LOG_ID_RADIO, prio, tag, fmt)
271 #define vprint_radio_log(prio, tag, fmt...) \
272 __dlog_vprint(LOG_ID_RADIO, prio, tag, fmt)
273 #define print_system_log(prio, tag, fmt...)\
274 __dlog_print(LOG_ID_SYSTEM, prio, tag, fmt)
275 #define vprint_system_log(prio, tag, fmt...) \
276 __dlog_vprint(LOG_ID_SYSTEM, prio, tag, fmt)
278 // ---------------------------------------------------------------------
279 // Don't use below macro no more!! It will be removed -- Verbose and Fatal priority macro will be removed --
280 #define COMPATIBILITY_ON
281 #ifdef COMPATIBILITY_ON
284 * @breif Conditional Macro.
285 * @remarks Don't use this macro. It's just compatibility.
286 * It will be deprecated.
288 #define LOGD_IF(cond, format, arg...) \
290 if (CONDITION(cond)) { \
291 LOGD(format, ##arg); \
294 #define LOGI_IF(cond, format, arg...) \
296 if (CONDITION(cond)) { \
297 LOGI(format, ##arg); \
300 #define LOGW_IF(cond, format, arg...) \
302 if (CONDITION(cond)) { \
303 LOGW(format, ##arg); \
306 #define LOGE_IF(cond, format, arg...) \
308 if (CONDITION(cond)) { \
309 LOGE(format, ##arg); \
312 #define LOGF_IF(cond, format, arg...) \
314 if (CONDITION(cond)) { \
315 LOGF(format, ##arg); \
318 #define SLOGD_IF(cond, format, arg...) \
320 if (CONDITION(cond)) { \
321 SLOGD(format, ##arg); \
324 #define SLOGI_IF(cond, format, arg...) \
326 if (CONDITION(cond)) { \
327 SLOGI(format, ##arg); \
330 #define SLOGW_IF(cond, format, arg...) \
332 if (CONDITION(cond)) { \
333 SLOGW(format, ##arg); \
336 #define SLOGE_IF(cond, format, arg...) \
338 if (CONDITION(cond)) { \
339 SLOGE(format, ##arg); \
342 #define SLOGF_IF(cond, format, arg...) \
344 if (CONDITION(cond)) { \
345 SLOGF(format, ##arg); \
348 #define RLOGD_IF(cond, format, arg...) \
350 if (CONDITION(cond)) { \
351 RLOGD(format, ##arg); \
354 #define RLOGI_IF(cond, format, arg...) \
356 if (CONDITION(cond)) { \
357 RLOGI(format, ##arg); \
360 #define RLOGW_IF(cond, format, arg...) \
362 if (CONDITION(cond)) { \
363 RLOGW(format, ##arg); \
366 #define RLOGE_IF(cond, format, arg...) \
368 if (CONDITION(cond)) { \
369 RLOGE(format, ##arg); \
372 #define RLOGF_IF(cond, format, arg...) \
374 if (CONDITION(cond)) { \
375 RLOGF(format, ##arg); \
378 #define LOG_ON() ({ do { } while (0); })
379 #define LOGV(format, arg...) NOP(format, ##arg)
380 #define SLOGV(format, arg...) NOP(format, ##arg)
381 #define RLOGV(format, arg...) NOP(format, ##arg)
382 #define ALOGV(format, arg...) NOP(format, ##arg)
383 #define LOGV_IF(cond, format, arg...) NOP(format, ##arg)
384 #define SLOGV_IF(cond, format, arg...) NOP(format, ##arg)
385 #define RLOGV_IF(cond, format, arg...) NOP(format, ##arg)
386 #define SECLOG(...) ({ do { } while (0); })
388 // ---------------------------------------------------------------------
391 * The stuff in the rest of this file should not be used directly.
396 * @details Use LOG(), SLOG(), RLOG() family
397 * not to use __dlog_print() directly
398 * @remarks Must not use this API directly. use macros instead.
399 * @param[in] log_id log device id
400 * @param[in] prio priority
402 * @param[in] fmt format string
403 * @return Operation result
404 * @retval 0>= Success
410 #define LOG_TAG USR_TAG
411 #include<dlog-internal.h>
412 __dlog_print(LOG_ID_MAIN, DLOG_INFO, USR_TAG, "you must not use this API directly");
415 int __dlog_print(log_id_t log_id, int prio, const char *tag, const char *fmt, ...);
419 * @brief Send log with va_list.
420 * @details Use LOG_VA(), SLOG_VA(), RLOG_VA() family
421 not to use __dlog_vprint() directly
422 * @remarks Must not use this API directly. use macros instead.
423 * @param[in] log_id log device id
424 * @param[in] prio priority
426 * @param[in] fmt format string
427 * @param[in] ap va_list
428 * @return Operation result
429 * @retval 0>= Success
435 #define LOG_TAG USR_TAG
436 #include<dlog-internal.h>
437 __dlog_vprint(LOG_ID_MAIN, DLOG_INFO, USR_TAG, "you must not use this API directly", ap);
440 int __dlog_vprint(log_id_t log_id, int prio, const char *tag, const char *fmt, va_list ap);
443 #endif /* __cplusplus */
444 #endif /* _DLOG_INTERNAL_H_*/