00cefbd9147d1bb9d48c736cb19a14fe6c8e2776
[platform/core/system/sensord.git] / src / sensorctl / log.h
1 /*
2  * sensorctl
3  *
4  * Copyright (c) 2017 Samsung Electronics Co., Ltd.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  */
19
20 #pragma once /* __LOG_H__ */
21
22 #include <stdio.h>
23 #include <glib.h>
24
25 #define _NRM  "\x1B[0m"
26 #define _RED  "\x1B[31m"
27 #define _GRN  "\x1B[32m"
28 #define _YEL  "\x1B[33m"
29 #define _BLU  "\x1B[34m"
30 #define _MAG  "\x1B[35m"
31 #define _CYN  "\x1B[36m"
32 #define _WHT  "\x1B[37m"
33 #define _RST "\033[0m"
34
35 #define _N(fmt, args...) \
36 do { \
37         g_print(fmt, ##args); \
38 } while (0)
39
40 #define _E(fmt, args...) \
41 do { \
42         g_print("\x1B[31m" fmt "\033[0m", ##args); \
43 } while (0)
44
45 #define _I(fmt, args...) \
46 do { \
47         g_print("\x1B[32m" fmt "\033[0m", ##args); \
48 } while (0)
49
50 #define WARN_IF(expr, fmt, arg...) \
51 do { \
52         if(expr) { \
53                 _E(fmt, ##arg); \
54         } \
55 } while (0)
56
57 #define RET_IF(expr) \
58 do { \
59         if(expr) { \
60                 return; \
61         } \
62 } while (0)
63
64 #define RETV_IF(expr, val) \
65 do { \
66         if(expr) { \
67                 return (val); \
68         } \
69 } while (0)
70
71 #define RETM_IF(expr, fmt, arg...) \
72 do { \
73         if(expr) { \
74                 _E(fmt, ##arg); \
75                 return; \
76         } \
77 } while (0)
78
79 #define RETVM_IF(expr, val, fmt, arg...) \
80 do { \
81         if(expr) { \
82                 _E(fmt, ##arg); \
83                 return (val); \
84         } \
85 } while (0)