Merge "apply config module"
[apps/native/tizen-things-daemon.git] / daemon / include / ttd-log.h
1 /*
2  * Copyright (c) 2018 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Flora License, Version 1.1 (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
7  *
8  * http://floralicense.org/license/
9  *
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.
15  */
16
17 #ifndef __TT_DAEMON_LOG_H__
18 #define __TT_DAEMON_LOG_H__
19
20 typedef enum {
21         TTD_LOG_UNKNOWN = 0,
22         TTD_LOG_VERBOSE,
23         TTD_LOG_DEBUG,
24         TTD_LOG_INFO,
25         TTD_LOG_WARNING,
26         TTD_LOG_ERROR,
27         TTD_LOG_LEVEL_MAX
28 } ttd_log_level_e;
29
30 typedef enum {
31         TTD_LOG_TYPE_DLOG = 0,
32         TTD_LOG_TYPE_FILE,
33         TTD_LOG_TYPE_ALL,
34 } ttd_log_type_e;
35
36 int ttd_log_print(ttd_log_level_e level, const char *tag, const char *fmt, ...);
37 int ttd_log_init(ttd_log_type_e type);
38 void ttd_log_fini(void);
39
40 #ifdef  LOG_TAG
41 #undef  LOG_TAG
42 #endif
43 #define LOG_TAG "TTD"
44
45 #if !defined(_V)
46 #define _V(fmt, arg...) ttd_log_print(TTD_LOG_VERBOSE, LOG_TAG, "[%s : %d] " fmt "\n", __func__, __LINE__, ##arg)
47 #endif
48
49 #if !defined(_D)
50 #define _D(fmt, arg...) ttd_log_print(TTD_LOG_DEBUG, LOG_TAG, "[%s : %d] " fmt "\n", __func__, __LINE__, ##arg)
51 #endif
52
53 #if !defined(_I)
54 #define _I(fmt, arg...) ttd_log_print(TTD_LOG_INFO, LOG_TAG, "[%s : %d] " fmt "\n", __func__, __LINE__, ##arg)
55 #endif
56
57 #if !defined(_W)
58 #define _W(fmt, arg...) ttd_log_print(TTD_LOG_WARNING, LOG_TAG, "[%s : %d] " fmt "\n", __func__, __LINE__, ##arg)
59 #endif
60
61 #if !defined(_E)
62 #define _E(fmt, arg...) ttd_log_print(TTD_LOG_ERROR, LOG_TAG, "[%s : %d] " fmt "\n", __func__, __LINE__, ##arg)
63 #endif
64
65 #define retvm_if(expr, val, fmt, arg...) do { \
66         if (expr) { \
67                 _E(fmt, ##arg); \
68                 _E("(%s) -> %s() return", #expr, __func__); \
69                 return val; \
70         } \
71 } while (0)
72
73 #define retv_if(expr, val) do { \
74         if (expr) { \
75                 _E("(%s) -> %s() return", #expr, __func__); \
76                 return (val); \
77         } \
78 } while (0)
79
80 #define retm_if(expr, fmt, arg...) do { \
81         if (expr) { \
82                 _E(fmt, ##arg); \
83                 _E("(%s) -> %s() return", #expr, __func__); \
84                 return; \
85         } \
86 } while (0)
87
88 #define ret_if(expr) do { \
89         if (expr) { \
90                 _E("(%s) -> %s() return", #expr, __func__); \
91                 return; \
92         } \
93 } while (0)
94
95 #define goto_if(expr, val) do { \
96         if (expr) { \
97                 _E("(%s) -> goto", #expr); \
98                 goto val; \
99         } \
100 } while (0)
101
102 #define break_if(expr) { \
103         if (expr) { \
104                 _E("(%s) -> break", #expr); \
105                 break; \
106         } \
107 }
108
109 #define continue_if(expr) { \
110         if (expr) { \
111                 _E("(%s) -> continue", #expr); \
112                 continue; \
113         } \
114 }
115
116 #endif /* __TT_DAEMON_LOG_H__ */