tizen 2.4 release
[framework/convergence/service/adaptors/storage-adaptor.git] / inc / storage-adaptor-log.h
1 /*
2 * Copyright (c) 2011 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
17 #ifndef __STORAGE_ADAPTOR_LOG_H__
18 #define __STORAGE_ADAPTOR_LOG_H__
19
20 /**
21  *  HOW TO USE IT:
22  *  First you need to set platform logging on the device:
23  *
24  *    # dlogctrl set platformlog 1
25  *
26  *  After reboot you are able to see logs from this application, when you launch dlogutil with a proper filter e.g.:
27  *
28  *    # dlogutil STORAGE_ADAPTOR:D
29  *
30  *  You may use different logging levels as: D (debug), I (info), W (warning), E (error) or F (fatal).
31  *  Higher level messages are included by default e.g. dlogutil CLOUDBOX:W prints warnings but also errors and fatal messages.
32  */
33
34 #include <unistd.h>
35 #include <linux/unistd.h>
36
37 /* These defines must be located before #include <dlog.h> */
38 #define TIZEN_ENGINEER_MODE
39 // TODO: Investigate why this macro is defined somewhere else
40 #ifndef TIZEN_DEBUG_ENABLE
41 #define TIZEN_DEBUG_ENABLE
42 #endif
43
44 #ifdef LOG_TAG
45 #undef LOG_TAG
46 #endif
47 /* Literal to filter logs from dlogutil */
48 #define LOG_TAG "STORAGE_ADAPTOR"
49
50 #include <dlog.h>
51
52 #ifdef __cplusplus
53 extern "C"
54 {
55 #endif /* __cplusplus */
56
57         /**
58          *  Colors of font
59          */
60 #define FONT_COLOR_RESET      "\033[0m"
61 #define FONT_COLOR_BLACK      "\033[30m"             /* Black */
62 #define FONT_COLOR_RED        "\033[31m"             /* Red */
63 #define FONT_COLOR_GREEN      "\033[32m"             /* Green */
64 #define FONT_COLOR_YELLOW     "\033[33m"             /* Yellow */
65 #define FONT_COLOR_BLUE       "\033[34m"             /* Blue */
66 #define FONT_COLOR_PURPLE     "\033[35m"             /* Purple */
67 #define FONT_COLOR_CYAN       "\033[36m"             /* Cyan */
68 #define FONT_COLOR_WHITE      "\033[37m"             /* White */
69 #define FONT_COLOR_BOLDBLACK  "\033[1m\033[30m"      /* Bold Black */
70 #define FONT_COLOR_BOLDRED    "\033[1m\033[31m"      /* Bold Red */
71 #define FONT_COLOR_BOLDGREEN  "\033[1m\033[32m"      /* Bold Green */
72 #define FONT_COLOR_BOLDYELLOW "\033[1m\033[33m"      /* Bold Yellow */
73 #define FONT_COLOR_BOLDBLUE   "\033[1m\033[34m"      /* Bold Blue */
74 #define FONT_COLOR_BOLDPURPLE "\033[1m\033[35m"      /* Bold Purple */
75 #define FONT_COLOR_BOLDCYAN   "\033[1m\033[36m"      /* Bold Cyan */
76 #define FONT_COLOR_BOLDWHITE  "\033[1m\033[37m"      /* Bold White */
77
78         /**
79          *  Gets thread ID
80          */
81 #define storage_adaptor_gettid() syscall(__NR_gettid)
82
83 /**
84  *  @brief Macro for returning value if expression is satisfied
85  *  @param[in]  expr Expression to be checked
86  *  @param[out] val  Value to be returned when expression is true
87  */
88 #define storage_adaptor_retv_if(expr, val) do { \
89             if(expr) { \
90                 LOGE(FONT_COLOR_PURPLE"[%d]"FONT_COLOR_RESET, storage_adaptor_gettid());    \
91                 return (val); \
92             } \
93         } while (0)
94
95 /**
96  * @brief Prints debug messages
97  * @param[in]  fmt  Format of data to be displayed
98  * @param[in]  args Arguments to be displayed
99  */
100 #define storage_adaptor_debug(fmt, arg...) do { \
101             LOGD(FONT_COLOR_GREEN"[%d]"fmt""FONT_COLOR_RESET, storage_adaptor_gettid(), ##arg);     \
102         } while (0)
103
104 /**
105  * @brief Prints info messages
106  * @param[in]  fmt  Format of data to be displayed
107  * @param[in]  args Arguments to be displayed
108  */
109 #define storage_adaptor_info(fmt, arg...) do { \
110             LOGI(FONT_COLOR_BLUE"[%d]"fmt""FONT_COLOR_RESET, storage_adaptor_gettid() ,##arg);     \
111         } while (0)
112
113 /**
114  * @brief Prints warning messages
115  * @param[in]  fmt  Format of data to be displayed
116  * @param[in]  args Arguments to be displayed
117  */
118 #define storage_adaptor_warning(fmt, arg...) do { \
119             LOGW(FONT_COLOR_YELLOW"[%d]"fmt""FONT_COLOR_RESET,storage_adaptor_gettid(), ##arg);     \
120         } while (0)
121
122 /**
123  * @brief Prints error messages
124  * @param[in]  fmt  Format of data to be displayed
125  * @param[in]  args Arguments to be displayed
126  */
127 #define storage_adaptor_error(fmt, arg...) do { \
128             LOGE(FONT_COLOR_RED"[%d]"fmt""FONT_COLOR_RESET,storage_adaptor_gettid(), ##arg);     \
129         } while (0)
130
131 /**
132  * @brief Prints fatal messages
133  * @param[in]  fmt  Format of data to be displayed
134  * @param[in]  args Arguments to be displayed
135  */
136 #define storage_adaptor_fatal(fmt, arg...) do { \
137             LOGF(FONT_COLOR_BOLDRED"[%d]"fmt""FONT_COLOR_RESET,storage_adaptor_gettid(), ##arg);     \
138         } while (0)
139
140 /**
141  * @brief Prints debug message on entry to particular function
142  * @param[in]  fmt  Format of data to be displayed
143  * @param[in]  args Arguments to be displayed
144  */
145 #define storage_adaptor_debug_func(fmt, arg...) do { \
146             LOGD(FONT_COLOR_CYAN"[%d]"fmt""FONT_COLOR_RESET, storage_adaptor_gettid(), ##arg);     \
147         } while (0)
148
149 /**
150  * @brief Prints debug message on entry to particular function
151  * @param[in]  fmt  Format of data to be displayed
152  * @param[in]  args Arguments to be displayed
153  */
154 #define storage_adaptor_debug_secure(fmt, arg...) do { \
155             SECURE_LOGD(FONT_COLOR_CYAN"[%d]"fmt""FONT_COLOR_RESET, storage_adaptor_gettid(), ##arg);     \
156         } while (0)
157
158 #define storage_adaptor_check_param_equal(compare, val, ret_val, exception_handling) {\
159         if ( compare == val ) {\
160                 LOGD(FONT_COLOR_PURPLE "[%d]<Line :%d>" "Parameter Check catched (equal) \n : Expected(%p) Value(%p)" FONT_COLOR_RESET, storage_adaptor_gettid(), __LINE__, compare, val);\
161                 exception_handling;\
162                 return ret_val;\
163         }\
164 }
165
166 #define plugin_req_enter()                      do { \
167                 storage_adaptor_info("[ENTER] plugin API call -)) -)) -)) -)) -)) -)) -)) -)) -)) -))"); \
168         } while (0)
169
170 #define plugin_req_exit(ret, plugin, error)     do { \
171                 storage_adaptor_info("[EXIT] plugin API called (%d) ((- ((- ((- ((- ((- ((- ((- ((- ((- ((-", (int)(ret)); \
172                 if ((error)) { \
173                         if ((*error)) { \
174                                 storage_adaptor_error("plugin issued error (%lld) (%s)", (long long int)((*error)->code), (char *)((*error)->msg)); \
175                                 char *tem = g_strdup_printf("[PLUGIN_ERROR] URI(%s), MSG(%s)", (char *)((plugin)->handle->plugin_uri), (char *)((*error)->msg)); \
176                                 if (tem) { \
177                                         free((*error)->msg); \
178                                         (*error)->msg = tem; \
179                                 } \
180                         } \
181                 } \
182         } while (0)
183
184 #define plugin_req_exit_void()                  do { \
185                 storage_adaptor_info("[EXIT] plugin API called ((- ((- ((- ((- ((- ((- ((- ((- ((- ((-"); \
186         } while (0)
187
188 #ifdef __cplusplus
189 }
190 #endif /* __cplusplus */
191
192 #endif /* __STORAGE_ADAPTOR_LOG_H__ */