de60f3ac3d64e7deaa6850477dce32b74cfa342a
[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 retvm_if(expr, val, fmt, arg...) do { \
46         if (expr) { \
47                 _E(fmt, ##arg); \
48                 _E("(%s) -> %s() return", #expr, __FUNCTION__); \
49                 return val; \
50         } \
51 } while (0)
52
53 #define retv_if(expr, val) do { \
54         if (expr) { \
55                 _E("(%s) -> %s() return", #expr, __FUNCTION__); \
56                 return (val); \
57         } \
58 } while (0)
59
60 #define retvm_error_message(expr, ret, val, fmt, arg...) do { \
61         if (expr) { \
62                 _E(fmt, ##arg); \
63                 _E("(%s) Error= {%s} -> %s() return", #expr, get_error_message(ret), __FUNCTION__); \
64                 return val; \
65         } \
66 } while (0)
67
68 #define retv_error_message(expr, ret) do { \
69         if (expr) { \
70                 _E("(%s) Error= {%s} -> %s() return", #expr, get_error_message(ret), __FUNCTION__); \
71                 return; \
72         } \
73 } while (0)
74
75 #define retm_if(expr, fmt, arg...) do { \
76         if (expr) { \
77                 _E(fmt, ##arg); \
78                 _E("(%s) -> %s() return", #expr, __FUNCTION__); \
79                 return; \
80         } \
81 } while (0)
82
83 #define ret_if(expr) do { \
84         if (expr) { \
85                 _E("(%s) -> %s() return", #expr, __FUNCTION__); \
86                 return; \
87         } \
88 } while (0)
89
90 #define goto_if(expr, val) do { \
91         if (expr) { \
92                 _E("(%s) -> goto", #expr); \
93                 goto val; \
94         } \
95 } while (0)
96
97 #define break_if(expr) { \
98         if (expr) { \
99                 _E("(%s) -> break", #expr); \
100                 break; \
101         } \
102 }
103
104 #define continue_if(expr) { \
105         if (expr) { \
106                 _E("(%s) -> continue", #expr); \
107                 continue; \
108         } \
109 }
110
111 typedef enum {
112         LOG_TYPE_DLOG = 0,
113         LOG_TYPE_FILE,
114         LOG_TYPE_ALL,
115 } log_type;
116
117 int log_print(log_priority prio, const char *tag, const char *fmt, ...);
118 int log_type_set(log_type type);
119 void log_file_close(void);
120
121 #endif /* __CAR_APP_LOG_H__ */