Fix to check SYSTEM_SETTINGS_KEY_AUTOMATIC_TIME_UPDATE feature
[platform/core/api/system-settings.git] / common / sst_log.h
1 /*
2  * Copyright (c) 2020 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 #pragma once
17
18 #define SST_LOG_RED "\033[31m"
19 #define SST_LOG_GREEN "\033[32m"
20 #define SST_LOG_BROWN "\033[33m"
21 #define SST_LOG_BLUE "\033[34m"
22 #define SST_LOG_END "\033[0m"
23
24 #undef __DBG
25 #undef __INFO
26 #undef __WARN
27 #undef __ERR
28
29 #undef _DBG
30 #undef _INFO
31 #undef _WARN
32 #undef _ERR
33
34 #undef DBG
35 #undef INFO
36 #undef WARN
37 #undef ERR
38
39 #ifdef SST_STDOUT
40 #include <stdio.h>
41 #include <string.h>
42 #define __FILENAME__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__)
43 #define __DBG(fmt, arg...) printf("[SST]%s(%d):" fmt "\n", __FILENAME__, __LINE__, ##arg)
44 #define __INFO(fmt, arg...) printf("[SST]%s(%d):" fmt "\n", __FILENAME__, __LINE__, ##arg)
45 #define __WARN(fmt, arg...) printf("[SST]%s(%d):" fmt "\n", __FILENAME__, __LINE__, ##arg)
46 #define __ERR(fmt, arg...) printf("[SST]%s(%d):" fmt "\n", __FILENAME__, __LINE__, ##arg)
47 #define __SECU_ERR(fmt, arg...) printf("[SST]%s(%d):" fmt "\n", __FILENAME__, __LINE__, ##arg)
48 #else
49 #define LOG_TAG "SYSTEM-SETTINGS"
50 #include <dlog.h>
51 #define __DBG(fmt, arg...) SLOGD(fmt, ##arg)
52 #define __INFO(fmt, arg...) SLOGI(fmt, ##arg)
53 #define __WARN(fmt, arg...) SLOGW(fmt, ##arg)
54 #define __ERR(fmt, arg...) SLOGE(fmt, ##arg)
55 #define __SECU_ERR(fmt, arg...) SECURE_SLOGE(fmt, ##arg)
56 #endif /* SST_STDOUT */
57
58 #ifdef SST_TEST
59 #define _DBG(fmt, arg...) __DBG(SST_LOG_BROWN "<Test>" SST_LOG_END fmt, ##arg)
60 #define _INFO(fmt, arg...) __INFO(SST_LOG_BLUE "<Test>" SST_LOG_END fmt, ##arg)
61 #define _WARN(fmt, arg...) __WARN(SST_LOG_GREEN "<Test>" SST_LOG_END fmt, ##arg)
62 #define _ERR(fmt, arg...) __ERR(SST_LOG_RED "<Test>" SST_LOG_END fmt, ##arg)
63 #else
64 #define _DBG(fmt, arg...) __DBG(fmt, ##arg)
65 #define _INFO(fmt, arg...) __INFO(fmt, ##arg)
66 #define _WARN(fmt, arg...) __WARN(fmt, ##arg)
67 #define _ERR(fmt, arg...) __ERR(fmt, ##arg)
68 #endif
69
70 #define SST_DEBUGGING
71
72 #ifdef SST_DEBUGGING
73 #define DBG(fmt, arg...) _DBG(fmt, ##arg)
74 #define WARN(fmt, arg...) _WARN(fmt, ##arg)
75 #define ERR(fmt, arg...) _ERR(fmt, ##arg)
76 #define INFO(fmt, arg...) _INFO(fmt, ##arg)
77 #define SECURE_ERR(fmt, arg...) __SECU_ERR(SST_LOG_GREEN fmt SST_LOG_END, ##arg)
78
79 #else /* SST_DEBUGGING */
80 #define DBG(fmt, arg...)
81 #define WARN(fmt, arg...)
82 #define ERR(fmt, arg...)
83 #define INFO(fmt, arg...)
84 #define SECURE_ERR(fmt, arg...)
85
86 #endif /* SST_DEBUGGING */
87
88 #define RET_IF(expr) \
89         do { \
90                 if (expr) { \
91                         ERR("(%s)", #expr); \
92                         return; \
93                 } \
94         } while (0)
95
96 #define RETV_IF(expr, val) \
97         do { \
98                 if (expr) { \
99                         ERR("(%s)", #expr); \
100                         return (val); \
101                 } \
102         } while (0)
103
104 #define RETM_IF(expr, fmt, arg...) \
105         do { \
106                 if (expr) { \
107                         ERR(fmt, ##arg); \
108                         return; \
109                 } \
110         } while (0)
111
112 #define RETVM_IF(expr, val, fmt, arg...) \
113         do { \
114                 if (expr) { \
115                         ERR(fmt, ##arg); \
116                         return (val); \
117                 } \
118         } while (0)
119
120 #define ERR_IF(expr) \
121         do { \
122                 if (expr) { \
123                         ERR("(%s)", #expr); \
124                 } \
125         } while (0)
126
127 #define WARN_IF(expr, fmt, arg...) \
128         do { \
129                 if (expr) { \
130                         WARN(fmt, ##arg); \
131                 } \
132         } while (0)