Tizen 2.4 SDK Rev6 Release
[framework/system/dlog.git] / include / dlog-internal.h
1 /*
2  * DLOG
3  * Copyright (c) 2005-2008, The Android Open Source Project
4  * Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
5  *
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
9  *
10  *     http://www.apache.org/licenses/LICENSE-2.0
11  *
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.
17  */
18
19 /**
20  * @file        dlog-internal.h
21  * @version     0.4
22  * @brief       This file is the header file of interface of dlog.
23  */
24 #ifndef _DLOG_INTERNAL_H_
25 #define _DLOG_INTERNAL_H_
26
27 #include <tizen_error.h>
28 #include <stdarg.h>
29 #include <string.h>
30
31 #include "dlog.h"
32
33 #ifdef __cplusplus
34 extern "C" {
35 #endif /* __cplusplus */
36
37 /*
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.
41  */
42 #ifndef LOG_TAG
43 #define LOG_TAG NULL
44 #endif
45
46 #ifndef __MODULE__
47 #define __MODULE__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__)
48 #endif
49
50 #ifdef TIZEN_ENGINEER_MODE
51 #ifndef TIZEN_DEBUG_ENABLE
52 #define TIZEN_DEBUG_ENABLE
53 #endif
54 #endif
55
56 /**
57  * @internal
58  * @brief log id
59  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
60  */
61 typedef enum {
62     LOG_ID_MAIN = 0,
63         LOG_ID_RADIO,
64         LOG_ID_SYSTEM,
65         LOG_ID_APPS,
66         LOG_ID_MAX
67 } log_id_t;
68
69 static inline int __dlog_no_print(const char *fmt __attribute__((unused)), ...) { return 0; }
70
71 #define CONDITION(cond)     (__builtin_expect((cond) != 0, 0))
72 #define NOP(...) ({ do { __dlog_no_print(__VA_ARGS__); } while (0); })
73
74 // Macro inner work---------------------------------------------------------------
75 #undef LOG_
76 #ifdef TIZEN_DEBUG_ENABLE
77 #define LOG_(id, prio, tag, fmt, arg...) \
78         ({ do { \
79                 __dlog_print(id, prio, tag, "%s: %s(%d) > " fmt, __MODULE__, __func__, __LINE__, ##arg); \
80         } while (0); })
81 #else
82 #define LOG_(id, prio, tag, fmt, arg...) \
83         ({ do { \
84                 if ((int)prio != DLOG_DEBUG) { \
85                         __dlog_print(id, prio, tag, "%s: %s(%d) > " fmt, __MODULE__, __func__, __LINE__, ##arg); \
86                 } \
87         } while (0); })
88 #endif
89
90 #undef SECURE_LOG_
91 #ifdef TIZEN_DEBUG_ENABLE
92 #define SECURE_LOG_(id, prio, tag, fmt, arg...) \
93         ({ do { \
94                 __dlog_print(id, prio, tag, "%s: %s(%d) > [SECURE_LOG] " fmt, __MODULE__, __func__, __LINE__, ##arg); \
95         } while (0); })
96 #else
97 #define SECURE_LOG_(id, prio, tag, fmt, arg...) NOP(fmt, ##arg)
98 #endif
99 // ---------------------------------------------------------------------
100 /**
101  * @internal
102  * @brief For Secure Log.
103  * @remarks Normally we strip Secure log from release builds.
104  * Please use this macros.
105  */
106 /**
107  * @internal
108  * @brief For Application and etc.
109  * @details Simplified macro to send a main log message using the current LOG_TAG.
110  * Example:
111  *  SECURE_LOGD("app debug %d", num);
112  *  SECURE_LOGE("app error %d", num);
113  */
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)
119 /**
120  * @internal
121  * @brief For Framework and system etc.
122  * @details Simplified macro to send a system log message using the current LOG_TAG.
123  * Example:
124  *  SECURE_SLOGD("system debug %d", num);
125  *  SECURE_SLOGE("system error %d", num);
126  */
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)
132 /**
133  * @internal
134  * @brief For Modem and radio etc.
135  * @details Simplified macro to send a radio log message using the current LOG_TAG.
136  * Example:
137  *  SECURE_RLOGD("radio debug %d", num);
138  *  SECURE_RLOGE("radio error %d", num);
139  */
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)
145 /**
146  * @internal
147  * @brief For Tizen OSP Application macro.
148  */
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)
154 /**
155  * @internal
156  * @details If you want use redefined macro.
157  * You can use this macro.
158  * This macro need priority and tag arguments.
159  */
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)
164
165 /**
166  * @internal
167  * @brief For Application and etc.
168  * @details Simplified macro to send a main log message using the current LOG_TAG.
169  * Example:
170  *  LOGD("app debug %d", num);
171  *  LOGE("app error %d", num);
172  */
173 #ifdef TIZEN_DEBUG_ENABLE
174 #define LOGD(format, arg...) LOG_(LOG_ID_MAIN, DLOG_DEBUG, LOG_TAG, format, ##arg)
175 #else
176 #define LOGD(format, arg...) NOP(format, ##arg)
177 #endif
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)
182 /**
183  * @internal
184  * @brief For Framework and system etc.
185  * @details Simplified macro to send a system log message using the current LOG_TAG.
186  * Example:
187  *  SLOGD("system debug %d", num);
188  *  SLOGE("system error %d", num);
189  */
190 #ifdef TIZEN_DEBUG_ENABLE
191 #define SLOGD(format, arg...) LOG_(LOG_ID_SYSTEM, DLOG_DEBUG, LOG_TAG, format, ##arg)
192 #else
193 #define SLOGD(format, arg...) NOP(format, ##arg)
194 #endif
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)
199 /**
200  * @internal
201  * @brief For Modem and radio etc.
202  * @details Simplified macro to send a radio log message using the current LOG_TAG.
203  * Example:
204  *  RLOGD("radio debug %d", num);
205  *  RLOGE("radio error %d", num);
206  */
207 #ifdef TIZEN_DEBUG_ENABLE
208 #define RLOGD(format, arg...) LOG_(LOG_ID_RADIO, DLOG_DEBUG, LOG_TAG, format, ##arg)
209 #else
210 #define RLOGD(format, arg...) NOP(format, ##arg)
211 #endif
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)
216 /**
217  * @internal
218  * @brief For Tizen OSP Application macro.
219  */
220 #ifdef TIZEN_DEBUG_ENABLE
221 #define ALOGD(format, arg...) LOG_(LOG_ID_APPS, DLOG_DEBUG, LOG_TAG, format, ##arg)
222 #else
223 #define ALOGD(format, arg...) NOP(format, ##arg)
224 #endif
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)
229
230 /**
231  * @internal
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))
236  *
237  * Example:
238  *  #define MYMACRO(prio, tag, format, arg...) \
239  *          LOG(prio, tag, format, ##arg)
240  *
241  *  MYMACRO(LOG_DEBUG, MYTAG, "test mymacro %d", num);
242  *
243  */
244 #ifndef LOG
245 #define LOG(priority, tag, format, arg...) LOG_(LOG_ID_MAIN, D##priority, tag, format, ##arg)
246 #endif
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)
250 /**
251  * @internal
252  */
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)
277
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
282 /**
283  * @internal
284  * @breif Conditional Macro.
285  * @remarks Don't use this macro. It's just compatibility.
286  * It will be deprecated.
287  */
288 #define LOGD_IF(cond, format, arg...) \
289         ({ do { \
290                 if (CONDITION(cond)) { \
291                         LOGD(format, ##arg); \
292                 } \
293         } while (0); })
294 #define LOGI_IF(cond, format, arg...) \
295         ({ do { \
296                 if (CONDITION(cond)) { \
297                         LOGI(format, ##arg); \
298                 } \
299         } while (0); })
300 #define LOGW_IF(cond, format, arg...) \
301         ({ do { \
302                 if (CONDITION(cond)) { \
303                         LOGW(format, ##arg); \
304                 } \
305         } while (0); })
306 #define LOGE_IF(cond, format, arg...) \
307         ({ do { \
308                 if (CONDITION(cond)) { \
309                         LOGE(format, ##arg); \
310                 } \
311         } while (0); })
312 #define LOGF_IF(cond, format, arg...) \
313         ({ do { \
314                 if (CONDITION(cond)) { \
315                         LOGF(format, ##arg); \
316                 } \
317         } while (0); })
318 #define SLOGD_IF(cond, format, arg...) \
319         ({ do { \
320                 if (CONDITION(cond)) { \
321                         SLOGD(format, ##arg); \
322                 } \
323         } while (0); })
324 #define SLOGI_IF(cond, format, arg...) \
325         ({ do { \
326                 if (CONDITION(cond)) { \
327                         SLOGI(format, ##arg); \
328                 } \
329         } while (0); })
330 #define SLOGW_IF(cond, format, arg...) \
331         ({ do { \
332                 if (CONDITION(cond)) { \
333                         SLOGW(format, ##arg); \
334                 } \
335         } while (0); })
336 #define SLOGE_IF(cond, format, arg...) \
337         ({ do { \
338                 if (CONDITION(cond)) { \
339                         SLOGE(format, ##arg); \
340                 } \
341         } while (0); })
342 #define SLOGF_IF(cond, format, arg...) \
343         ({ do { \
344                 if (CONDITION(cond)) { \
345                         SLOGF(format, ##arg); \
346                 } \
347         } while (0); })
348 #define RLOGD_IF(cond, format, arg...) \
349         ({ do { \
350                 if (CONDITION(cond)) { \
351                         RLOGD(format, ##arg); \
352                 } \
353         } while (0); })
354 #define RLOGI_IF(cond, format, arg...) \
355         ({ do { \
356                 if (CONDITION(cond)) { \
357                         RLOGI(format, ##arg); \
358                 } \
359         } while (0); })
360 #define RLOGW_IF(cond, format, arg...) \
361         ({ do { \
362                 if (CONDITION(cond)) { \
363                         RLOGW(format, ##arg); \
364                 } \
365         } while (0); })
366 #define RLOGE_IF(cond, format, arg...) \
367         ({ do { \
368                 if (CONDITION(cond)) { \
369                         RLOGE(format, ##arg); \
370                 } \
371         } while (0); })
372 #define RLOGF_IF(cond, format, arg...) \
373         ({ do { \
374                 if (CONDITION(cond)) { \
375                         RLOGF(format, ##arg); \
376                 } \
377         } while (0); })
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); })
387 #endif
388 // ---------------------------------------------------------------------
389
390 /*
391  * The stuff in the rest of this file should not be used directly.
392  */
393 /**
394  * @internal
395  * @brief     Send log.
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
401  * @param[in] tag tag
402  * @param[in] fmt format string
403  * @return    Operation result
404  * @retval    0>= Success
405  * @retval    -1  Error
406  * @pre       none
407  * @post      none
408  * @see       __dlog_print
409  * @code
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");
413  * @endcode
414  */
415 int __dlog_print(log_id_t log_id, int prio, const char *tag, const char *fmt, ...);
416
417 /**
418  * @internal
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
425  * @param[in] tag tag
426  * @param[in] fmt format string
427  * @param[in] ap va_list
428  * @return    Operation result
429  * @retval    0>= Success
430  * @retval    -1  Error
431  * @pre       none
432  * @post      none
433  * @see       __dlog_vprint
434  * @code
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);
438  * @endcode
439   */
440 int __dlog_vprint(log_id_t log_id, int prio, const char *tag, const char *fmt, va_list ap);
441 #ifdef __cplusplus
442 }
443 #endif /* __cplusplus */
444 #endif /* _DLOG_INTERNAL_H_*/