Fix enum (IOTCON_OBSERVE -> IOTCON_OBSERVE_IGNORE_OUT_OF_ORDER)
[platform/core/iot/iotcon.git] / common / ic-log.h
1 /*
2  * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (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://www.apache.org/licenses/LICENSE-2.0
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 #ifndef __IOT_CONNECTIVITY_MANAGER_INTERNAL_LOG_H__
17 #define __IOT_CONNECTIVITY_MANAGER_INTERNAL_LOG_H__
18
19 #define IC_LOG_RED "\033[0;31m"
20 #define IC_LOG_GREEN "\033[0;32m"
21 #define IC_LOG_BROWN "\033[0;33m"
22 #define IC_LOG_BLUE "\033[0;34m"
23 #define IC_LOG_END "\033[0;m"
24
25 #undef _DBG
26 #undef _INFO
27 #undef _WARN
28 #undef _ERR
29
30 #undef DBG
31 #undef INFO
32 #undef WARN
33 #undef ERR
34
35 #define TIZEN_DEBUG_ENABLE
36 #define LOG_TAG "IOTCON"
37 #include <dlog.h>
38
39 #ifdef IC_DAEMON
40
41 #define _DBG(fmt, arg...) SLOGD(IC_LOG_GREEN "<Daemon>" IC_LOG_END fmt, ##arg)
42 #define _INFO(fmt, arg...) SLOGI(IC_LOG_GREEN "<Daemon>" IC_LOG_END fmt, ##arg)
43 #define _WARN(fmt, arg...) SLOGW(IC_LOG_GREEN "<Daemon>" IC_LOG_END fmt, ##arg)
44 #define _ERR(fmt, arg...) SLOGE(IC_LOG_GREEN "<Daemon>" IC_LOG_END fmt, ##arg)
45
46 #else /* IC_DAEMON */
47
48 #define _DBG(fmt, arg...) SLOGD(fmt, ##arg)
49 #define _INFO(fmt, arg...) SLOGI(fmt, ##arg)
50 #define _WARN(fmt, arg...) SLOGW(fmt, ##arg)
51 #define _ERR(fmt, arg...) SLOGE(fmt, ##arg)
52
53 #endif /* IC_DAEMON */
54
55 #if 0
56 #define _DBG(fmt, arg...) \
57         printf("[IoTCon]%s(%d):" fmt "\n", __FUNCTION__, __LINE__, ##arg)
58 #define _INFO(fmt, arg...) \
59         printf("[IoTCon]%s(%d):" fmt "\n", __FUNCTION__, __LINE__, ##arg)
60 #define _WARN(fmt, arg...) \
61         printf("[IoTCon]%s(%d):" fmt "\n", __FUNCTION__, __LINE__, ##arg)
62 #define _ERR(fmt, arg...) \
63         printf("[IoTCon]%s(%d):" fmt "\n", __FUNCTION__, __LINE__, ##arg)
64 #endif
65
66 #define IC_DEBUGGING
67
68 #ifdef IC_DEBUGGING
69
70 #define FN_CALL _INFO(">>>>>>>> called")
71 #define FN_END _INFO("<<<<<<<< ended")
72 #define DBG(fmt, arg...) _DBG(fmt, ##arg)
73 #define WARN(fmt, arg...) _WARN(IC_LOG_BROWN fmt IC_LOG_END, ##arg)
74 #define ERR(fmt, arg...) _ERR(IC_LOG_RED fmt IC_LOG_END, ##arg)
75 #define INFO(fmt, arg...) _INFO(IC_LOG_BLUE fmt IC_LOG_END, ##arg)
76 #define SECURE_DBG(fmt, arg...) SECURE_SLOGD(fmt, ##arg)
77 #define SECURE_ERR(fmt, arg...) SECURE_SLOGE(fmt, ##arg)
78
79 #else /* IC_DEBUGGING */
80
81 #define FN_CALL
82 #define FN_END
83 #define DBG(fmt, arg...)
84 #define WARN(fmt, arg...)
85 #define ERR(fmt, arg...) _ERR(fmt, ##arg)
86 #define INFO(fmt, arg...)
87 #define SECURE_DBG(fmt, arg...)
88 #define SECURE_ERR(fmt, arg...) SECURE_SLOGE(fmt, ##arg)
89
90 #endif /* IC_DEBUGGING */
91
92 #define RET_IF(expr) \
93         do { \
94                 if (expr) { \
95                         ERR("(%s)", #expr); \
96                         return; \
97                 }\
98         } while(0)
99
100 #define RETV_IF(expr, val) \
101         do {\
102                 if (expr) { \
103                         ERR("(%s)", #expr); \
104                         return (val); \
105                 } \
106         } while(0)
107
108 #define RETM_IF(expr, fmt, arg...) \
109         do {\
110                 if (expr) { \
111                         ERR(fmt, ##arg); \
112                         return; \
113                 }\
114         } while(0)
115
116 #define RETVM_IF(expr, val, fmt, arg...) \
117         do {\
118                 if (expr) { \
119                         ERR(fmt, ##arg); \
120                         return (val); \
121                 } \
122         } while(0)
123
124 #define ERR_IF(expr) \
125         do { \
126                 if (expr) { \
127                         ERR("(%s)", #expr); \
128                 } \
129         } while (0)
130
131 #define WARN_IF(expr, fmt, arg...) \
132         do { \
133                 if (expr) { \
134                         WARN(fmt, ##arg); \
135                 } \
136         } while (0)
137
138 #endif /* __IOT_CONNECTIVITY_MANAGER_INTERNAL_LOG_H__ */