apply tizen coding rule
[platform/core/uifw/libtdm.git] / include / tdm_log.h
1 /**************************************************************************
2  *
3  * libtdm
4  *
5  * Copyright 2015 Samsung Electronics co., Ltd. All Rights Reserved.
6  *
7  * Contact: Eunchul Kim <chulspro.kim@samsung.com>,
8  *          JinYoung Jeon <jy0.jeon@samsung.com>,
9  *          Taeheon Kim <th908.kim@samsung.com>,
10  *          YoungJun Cho <yj44.cho@samsung.com>,
11  *          SooChan Lim <sc1.lim@samsung.com>,
12  *          Boram Park <sc1.lim@samsung.com>
13  *
14  * Permission is hereby granted, free of charge, to any person obtaining a
15  * copy of this software and associated documentation files (the
16  * "Software"), to deal in the Software without restriction, including
17  * without limitation the rights to use, copy, modify, merge, publish,
18  * distribute, sub license, and/or sell copies of the Software, and to
19  * permit persons to whom the Software is furnished to do so, subject to
20  * the following conditions:
21  *
22  * The above copyright notice and this permission notice (including the
23  * next paragraph) shall be included in all copies or substantial portions
24  * of the Software.
25  *
26  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
27  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
28  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
29  * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
30  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
31  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
32  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
33  *
34 **************************************************************************/
35
36 #ifndef _TDM_LOG_H_
37 #define _TDM_LOG_H_
38
39
40 #ifdef __cplusplus
41 extern "C" {
42 #endif
43
44 #include <unistd.h>
45 #include <time.h>
46 #include <assert.h>
47 #include <sys/syscall.h>
48
49
50 /**
51  * @file tdm_log.h
52  * @brief The header file to print logs in frontend and backend modules
53  * @details
54  * The TDM debug log can be enable by setting "TDM_DEBUG" enviroment
55  * @par Example
56  * @code
57  *  $ export TDM_DEBUG=1
58  * @endcode
59  */
60 extern int tdm_debug;
61
62 //#define TDM_CONFIG_DLOG
63 //#define TDM_CONFIG_ASSERT
64
65 #undef TDM_ASSERT
66 #ifdef TDM_CONFIG_ASSERT
67 #define TDM_ASSERT(o) assert(o)
68 #else
69 #define TDM_ASSERT(o)
70 #endif
71
72 #ifdef TDM_CONFIG_DLOG
73
74 #include <dlog.h>
75
76 #ifdef LOG_TAG
77 #undef LOG_TAG
78 #endif
79 #define LOG_TAG "TDM"
80
81 #define TDM_DBG(fmt, args...) \
82         if (tdm_debug) \
83         do { \
84                 struct timespec ts;     \
85                 clock_gettime(CLOCK_MONOTONIC, &ts);    \
86                 LOGD("[%d.%06d] "fmt"\n", (int)ts.tv_sec, (int)ts.tv_nsec / 1000, ##args);      \
87                 printf("[TDM_DBG][%d.%06d][%d][%s %d] "fmt"\n", (int)ts.tv_sec, \
88                         (int)ts.tv_nsec / 1000, (int)syscall(SYS_gettid), __func__, __LINE__, ##args); \
89         } while (0);
90
91 #define TDM_INFO(fmt, args...) \
92         do { \
93                 struct timespec ts;     \
94                 clock_gettime(CLOCK_MONOTONIC, &ts);    \
95                 LOGI("[%d.%06d] "fmt"\n", (int)ts.tv_sec, (int)ts.tv_nsec / 1000, ##args);      \
96                 printf("[TDM_INF][%d.%06d][%d][%s %d] "fmt"\n", (int)ts.tv_sec, \
97                         (int)ts.tv_nsec / 1000, (int)syscall(SYS_gettid), __func__, __LINE__, ##args); \
98         } while (0);
99
100 #define TDM_WRN(fmt, args...) \
101         do { \
102                 struct timespec ts;     \
103                 clock_gettime(CLOCK_MONOTONIC, &ts);    \
104                 LOGI("[%d.%06d] "fmt"\n", (int)ts.tv_sec, (int)ts.tv_nsec / 1000, ##args);      \
105                 printf("[TDM_WRN][%d.%06d][%d][%s %d] "fmt"\n", (int)ts.tv_sec, \
106                         (int)ts.tv_nsec / 1000, (int)syscall(SYS_gettid), __func__, __LINE__, ##args); \
107         } while (0);
108
109 #define TDM_ERR(fmt, args...) \
110         do { \
111                 struct timespec ts;     \
112                 clock_gettime(CLOCK_MONOTONIC, &ts);    \
113                 LOGE("[%d.%06d] "fmt"\n", (int)ts.tv_sec, (int)ts.tv_nsec / 1000, ##args);      \
114                 printf("[TDM_ERR][%d.%06d][%d][%s %d] "fmt"\n", (int)ts.tv_sec, \
115                         (int)ts.tv_nsec / 1000, (int)syscall(SYS_gettid), __func__, __LINE__, ##args); \
116         } while (0);
117
118 #else /* TDM_CONFIG_DLOG */
119
120 #include <stdio.h>
121
122 #define COLOR_RED "\x1b[31m"      /* for error */
123 #define COLOR_YELLOW "\x1b[33m"   /* for warning */
124 #define COLOR_GREEN "\x1b[32m"    /* for info */
125 #define COLOR_RESET "\x1b[0m"
126
127 #define TDM_DBG(fmt, args...) \
128         if (tdm_debug) \
129         do { \
130                 struct timespec ts;     \
131                 clock_gettime(CLOCK_MONOTONIC, &ts);    \
132                 printf("[TDM_DBG][%d.%06d][%d][%s %d] "fmt"\n", (int)ts.tv_sec, \
133                         (int)ts.tv_nsec / 1000, (int)syscall(SYS_gettid), __func__, __LINE__, ##args); \
134         } while (0);
135
136 #define TDM_INFO(fmt, args...) \
137         do { \
138                 struct timespec ts;     \
139                 clock_gettime(CLOCK_MONOTONIC, &ts);    \
140                 printf(COLOR_GREEN"[TDM_INF]"COLOR_RESET"[%d.%06d][%d][%s %d] "fmt"\n", (int)ts.tv_sec, \
141                         (int)ts.tv_nsec / 1000, (int)syscall(SYS_gettid), __func__, __LINE__, ##args); \
142         } while (0);
143
144 #define TDM_WRN(fmt, args...) \
145         do { \
146                 struct timespec ts;     \
147                 clock_gettime(CLOCK_MONOTONIC, &ts);    \
148                 printf(COLOR_YELLOW"[TDM_WRN]"COLOR_RESET"[%d.%06d][%d][%s %d] "fmt"\n", (int)ts.tv_sec,        \
149                         (int)ts.tv_nsec / 1000, (int)syscall(SYS_gettid), __func__, __LINE__, ##args); \
150                 TDM_ASSERT(0); \
151         } while (0);
152
153 #define TDM_ERR(fmt, args...) \
154         do { \
155                 struct timespec ts;     \
156                 clock_gettime(CLOCK_MONOTONIC, &ts);    \
157                 printf(COLOR_RED"[TDM_ERR]"COLOR_RESET"[%d.%06d][%d][%s %d] "fmt"\n", (int)ts.tv_sec,   \
158                         (int)ts.tv_nsec / 1000, (int)syscall(SYS_gettid), __func__, __LINE__, ##args); \
159                 TDM_ASSERT(0); \
160         } while (0);
161
162 #endif /* TDM_CONFIG_DLOG */
163
164 #ifdef __cplusplus
165 }
166 #endif
167
168 #endif /* _TDM_LOG_H_ */