log: move the condition check to tbm_log.h
[platform/core/uifw/libtbm.git] / src / tbm_log.h
1 /**************************************************************************
2
3 libtbm
4
5 Copyright 2018 Samsung Electronics co., Ltd. All Rights Reserved.
6
7 Contact: SooChan Lim <sc1.lim@samsung.com>, Sangjin Lee <lsj119@samsung.com>
8 Boram Park <boram1288.park@samsung.com>, Changyeon Lee <cyeon.lee@samsung.com>
9
10 Permission is hereby granted, free of charge, to any person obtaining a
11 copy of this software and associated documentation files (the
12 "Software"), to deal in the Software without restriction, including
13 without limitation the rights to use, copy, modify, merge, publish,
14 distribute, sub license, and/or sell copies of the Software, and to
15 permit persons to whom the Software is furnished to do so, subject to
16 the following conditions:
17
18 The above copyright notice and this permission notice (including the
19 next paragraph) shall be included in all copies or substantial portions
20 of the Software.
21
22 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
23 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
25 IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
26 ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
27 TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
28 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29
30 **************************************************************************/
31
32 #ifndef _TBM_LOG_H_
33 #define _TBM_LOG_H_
34
35 #include <unistd.h>
36 #include <sys/syscall.h>
37 #include <time.h>
38 #include <dlog.h>
39
40 #ifdef __cplusplus
41 extern "C" {
42 #endif
43
44 /**
45  * @file tbm_log.h
46  * @brief The header file to print logs in frontend and backend modules
47  * @details
48  */
49
50 enum {
51         TBM_LOG_LEVEL_NONE,
52         TBM_LOG_LEVEL_ERR,
53         TBM_LOG_LEVEL_WRN,
54         TBM_LOG_LEVEL_INFO,
55         TBM_LOG_LEVEL_DBG,
56 };
57
58 void tbm_log_enable_color(unsigned int enable);
59 void tbm_log_enable_dlog(unsigned int enable);
60 void tbm_log_enable_debug(unsigned int enable);
61 void tbm_log_set_debug_level(int level);
62 void tbm_log_set_assert_level(int level);
63 void tbm_log_set_path(const char *path);
64 void tbm_log_print(int level, const char *fmt, ...);
65 void tbm_log_reset(void);
66
67 #define TBM_DBG(fmt, args...) \
68         do { \
69                 struct timespec ts; \
70                 clock_gettime(CLOCK_MONOTONIC, &ts); \
71                 tbm_log_print(TBM_LOG_LEVEL_DBG, "[%5d.%06d][%d][%s %d]"fmt, \
72                                           (int)ts.tv_sec, (int)ts.tv_nsec / 1000, \
73                                           (int)syscall(SYS_gettid), __FUNCTION__, __LINE__, ##args);  \
74         } while (0)
75 #define TBM_INFO(fmt, args...) \
76         do { \
77                 struct timespec ts; \
78                 clock_gettime(CLOCK_MONOTONIC, &ts); \
79                 tbm_log_print(TBM_LOG_LEVEL_INFO, "[%5d.%06d][%d][%s %d]"fmt, \
80                                           (int)ts.tv_sec, (int)ts.tv_nsec / 1000, \
81                                           (int)syscall(SYS_gettid), __FUNCTION__, __LINE__, ##args);  \
82         } while (0)
83 #define TBM_WRN(fmt, args...) \
84         do { \
85                 struct timespec ts; \
86                 clock_gettime(CLOCK_MONOTONIC, &ts); \
87                 tbm_log_print(TBM_LOG_LEVEL_WRN, "[%5d.%06d][%d][%s %d]"fmt, \
88                                           (int)ts.tv_sec, (int)ts.tv_nsec / 1000, \
89                                           (int)syscall(SYS_gettid), __FUNCTION__, __LINE__, ##args);  \
90         } while (0)
91 #define TBM_ERR(fmt, args...) \
92         do { \
93                 struct timespec ts; \
94                 clock_gettime(CLOCK_MONOTONIC, &ts); \
95                 tbm_log_print(TBM_LOG_LEVEL_ERR, "[%5d.%06d][%d][%s %d]"fmt, \
96                                           (int)ts.tv_sec, (int)ts.tv_nsec / 1000, \
97                                           (int)syscall(SYS_gettid), __FUNCTION__, __LINE__, ##args);  \
98         } while (0)
99
100 #define TBM_NEVER_GET_HERE() TBM_WRN("** NEVER GET HERE **")
101 #define TBM_DEPRECATED(str) \
102         do { \
103                 if (str) \
104                         TBM_WRN("** DEPRECATED: %s **", str); \
105                 else \
106                         TBM_WRN("** DEPRECATED **"); \
107         } while(0)
108
109 /* check condition */
110 #define TBM_RETURN_IF_FAIL(cond) {\
111         if (!(cond)) {\
112                 TBM_ERR("'%s' failed.\n", #cond);\
113                 return;\
114         } \
115 }
116 #define TBM_RETURN_VAL_IF_FAIL(cond, val) {\
117         if (!(cond)) {\
118                 TBM_ERR("'%s' failed.\n", #cond);\
119                 return val;\
120         } \
121 }
122 #define TBM_GOTO_VAL_IF_FAIL(cond, val) {\
123         if (!(cond)) {\
124                 TBM_ERR("'%s' failed.\n", #cond);\
125                 goto val;\
126         } \
127 }
128
129 #ifdef __cplusplus
130 }
131 #endif
132
133 #endif /* _TBM_LOG_H_ */