Code fixes. Some logs added
[apps/native/gear-racing-car.git] / inc / log.h
1 /*
2  * Copyright (c) 2017 Samsung Electronics Co., Ltd.
3  *
4  * Contact: Jeonghoon Park <jh1979.park@samsung.com>
5  *
6  * Licensed under the Flora License, Version 1.1 (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://floralicense.org/license/
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 #ifndef __CAR_APP_LOG_H__
20 #define __CAR_APP_LOG_H__
21
22 #include <dlog.h>
23
24 #ifdef  LOG_TAG
25 #undef  LOG_TAG
26 #endif
27 #define LOG_TAG "CAR_APP"
28
29 #if !defined(_D)
30 #define _D(fmt, arg...) log_print(DLOG_DEBUG, LOG_TAG, "[%s:%d] " fmt "\n", __func__, __LINE__, ##arg)
31 #endif
32
33 #if !defined(_I)
34 #define _I(fmt, arg...) log_print(DLOG_INFO, LOG_TAG, "[%s:%d] " fmt "\n", __func__, __LINE__, ##arg)
35 #endif
36
37 #if !defined(_W)
38 #define _W(fmt, arg...) log_print(DLOG_WARN, LOG_TAG, "[%s:%d] " fmt "\n", __func__, __LINE__, ##arg)
39 #endif
40
41 #if !defined(_E)
42 #define _E(fmt, arg...) log_print(DLOG_ERROR, LOG_TAG, "[%s:%d] " fmt "\n", __func__, __LINE__, ##arg)
43 #endif
44
45 #define FUNCTION_START _D("\033[0;32m ***************************** START ***************************** \033[0m")
46 #define FUNCTION_END   _D("\033[0;32m *****************************  END  ***************************** \033[0m")
47
48 #define retvm_if(expr, val, fmt, arg...) do { \
49         if (expr) { \
50                 _E(fmt, ##arg); \
51                 _E("(%s) -> %s() return", #expr, __FUNCTION__); \
52                 return val; \
53         } \
54 } while (0)
55
56 #define retv_if(expr, val) do { \
57         if (expr) { \
58                 _E("(%s) -> %s() return", #expr, __FUNCTION__); \
59                 return (val); \
60         } \
61 } while (0)
62
63 #define retv_error_message(expr, err, ret) do { \
64         if (expr) { \
65                 _E("(%s) Error= {%s} -> %s() return", #expr, get_error_message(err), __FUNCTION__); \
66                 return ret; \
67         } \
68 } while (0)
69
70 #define ret_error_message(expr, ret) do { \
71         if (expr) { \
72                 _E("(%s) Error= {%s} -> %s() return", #expr, get_error_message(ret), __FUNCTION__); \
73                 return; \
74         } \
75 } while (0)
76
77 #define retm_if(expr, fmt, arg...) do { \
78         if (expr) { \
79                 _E(fmt, ##arg); \
80                 _E("(%s) -> %s() return", #expr, __FUNCTION__); \
81                 return; \
82         } \
83 } while (0)
84
85 #define ret_if(expr) do { \
86         if (expr) { \
87                 _E("(%s) -> %s() return", #expr, __FUNCTION__); \
88                 return; \
89         } \
90 } while (0)
91
92 #define goto_if(expr, val) do { \
93         if (expr) { \
94                 _E("(%s) -> goto", #expr); \
95                 goto val; \
96         } \
97 } while (0)
98
99 #define break_if(expr) { \
100         if (expr) { \
101                 _E("(%s) -> break", #expr); \
102                 break; \
103         } \
104 }
105
106 #define continue_if(expr) { \
107         if (expr) { \
108                 _E("(%s) -> continue", #expr); \
109                 continue; \
110         } \
111 }
112
113 typedef enum {
114         LOG_TYPE_DLOG = 0,
115         LOG_TYPE_FILE,
116         LOG_TYPE_ALL,
117 } log_type;
118
119 int log_print(log_priority prio, const char *tag, const char *fmt, ...);
120 int log_type_set(log_type type);
121 void log_file_close(void);
122
123 #endif /* __CAR_APP_LOG_H__ */