tizen 2.4 release
[framework/convergence/service/service-plugin-client.git] / include / libservice_plugin_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 __LIB_SERVICE_PLUGIN_LOG_H__
18 #define __LIB_SERVICE_PLUGIN_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 HELLO_WORLD_TEMP: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 "LIBSERVICE_PLUGIN"
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 LSP_LOG_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 LSP_LOG_retv_if(expr, val) do { \
89             if(expr) { \
90                 LOGE(FONT_COLOR_PURPLE"[%d]"FONT_COLOR_RESET, LSP_LOG_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 LSP_LOG_debug(fmt, arg...) do { \
101             LOGD(FONT_COLOR_GREEN"[%d]"fmt""FONT_COLOR_RESET, LSP_LOG_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 LSP_LOG_info(fmt, arg...) do { \
110             LOGI(FONT_COLOR_BLUE"[%d]"fmt""FONT_COLOR_RESET, LSP_LOG_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 LSP_LOG_warning(fmt, arg...) do { \
119             LOGW(FONT_COLOR_YELLOW"[%d]"fmt""FONT_COLOR_RESET,LSP_LOG_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 LSP_LOG_error(fmt, arg...) do { \
128             LOGE(FONT_COLOR_RED"[%d]"fmt""FONT_COLOR_RESET,LSP_LOG_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 LSP_LOG_fatal(fmt, arg...) do { \
137             LOGF(FONT_COLOR_BOLDRED"[%d]"fmt""FONT_COLOR_RESET,LSP_LOG_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 LSP_LOG_debug_func(fmt, arg...) do { \
146             LOGD(FONT_COLOR_CYAN"[%d]"fmt""FONT_COLOR_RESET, LSP_LOG_gettid(), ##arg);     \
147         } while (0)
148
149 #ifdef __cplusplus
150 }
151 #endif /* __cplusplus */
152
153 #endif /* __LIB_SERVICE_PLUGIN_LOG_H__ */