Add read-only interface
[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 #if __WORDSIZE == 64
80 #define DBG_HANDLE(handle) _DBG("handle : %lld", #handle)
81 #else
82 #define DBG_HANDLE(handle) _DBG("handle : %d", #handle)
83 #endif
84
85 #else /* IC_DEBUGGING */
86
87 #define FN_CALL
88 #define FN_END
89 #define DBG(fmt, arg...)
90 #define WARN(fmt, arg...)
91 #define ERR(fmt, arg...) _ERR(fmt, ##arg)
92 #define INFO(fmt, arg...)
93 #define SECURE_DBG(fmt, arg...)
94 #define SECURE_ERR(fmt, arg...) SECURE_SLOGE(fmt, ##arg)
95
96 #endif /* IC_DEBUGGING */
97
98 #define RET_IF(expr) \
99         do { \
100                 if (expr) { \
101                         ERR("(%s)", #expr); \
102                         return; \
103                 }\
104         } while(0)
105
106 #define RETV_IF(expr, val) \
107         do {\
108                 if (expr) { \
109                         ERR("(%s)", #expr); \
110                         return (val); \
111                 } \
112         } while(0)
113
114 #define RETM_IF(expr, fmt, arg...) \
115         do {\
116                 if (expr) { \
117                         ERR(fmt, ##arg); \
118                         return; \
119                 }\
120         } while(0)
121
122 #define RETVM_IF(expr, val, fmt, arg...) \
123         do {\
124                 if (expr) { \
125                         ERR(fmt, ##arg); \
126                         return (val); \
127                 } \
128         } while(0)
129
130 #define ERR_IF(expr) \
131         do { \
132                 if (expr) { \
133                         ERR("(%s)", #expr); \
134                 } \
135         } while (0)
136
137 #define WARN_IF(expr, fmt, arg...) \
138         do { \
139                 if (expr) { \
140                         WARN(fmt, ##arg); \
141                 } \
142         } while (0)
143
144 #endif /* __IOT_CONNECTIVITY_MANAGER_INTERNAL_LOG_H__ */