2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #ifndef __LIB_SERVICE_PLUGIN_LOG_H__
18 #define __LIB_SERVICE_PLUGIN_LOG_H__
22 * First you need to set platform logging on the device:
24 * # dlogctrl set platformlog 1
26 * After reboot you are able to see logs from this application, when you launch dlogutil with a proper filter e.g.:
28 * # dlogutil HELLO_WORLD_TEMP:D
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.
35 #include <linux/unistd.h>
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
47 /* Literal to filter logs from dlogutil */
48 #define LOG_TAG "LIBSERVICE_PLUGIN"
55 #endif /* __cplusplus */
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 */
81 #define LSP_LOG_gettid() syscall(__NR_gettid)
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
88 #define LSP_LOG_retv_if(expr, val) do { \
90 LOGE(FONT_COLOR_PURPLE"[%d]"FONT_COLOR_RESET, LSP_LOG_gettid()); \
96 * @brief Prints debug messages
97 * @param[in] fmt Format of data to be displayed
98 * @param[in] args Arguments to be displayed
100 #define LSP_LOG_debug(fmt, arg...) do { \
101 LOGD(FONT_COLOR_GREEN"[%d]"fmt""FONT_COLOR_RESET, LSP_LOG_gettid(), ##arg); \
105 * @brief Prints info messages
106 * @param[in] fmt Format of data to be displayed
107 * @param[in] args Arguments to be displayed
109 #define LSP_LOG_info(fmt, arg...) do { \
110 LOGI(FONT_COLOR_BLUE"[%d]"fmt""FONT_COLOR_RESET, LSP_LOG_gettid() ,##arg); \
114 * @brief Prints warning messages
115 * @param[in] fmt Format of data to be displayed
116 * @param[in] args Arguments to be displayed
118 #define LSP_LOG_warning(fmt, arg...) do { \
119 LOGW(FONT_COLOR_YELLOW"[%d]"fmt""FONT_COLOR_RESET,LSP_LOG_gettid(), ##arg); \
123 * @brief Prints error messages
124 * @param[in] fmt Format of data to be displayed
125 * @param[in] args Arguments to be displayed
127 #define LSP_LOG_error(fmt, arg...) do { \
128 LOGE(FONT_COLOR_RED"[%d]"fmt""FONT_COLOR_RESET,LSP_LOG_gettid(), ##arg); \
132 * @brief Prints fatal messages
133 * @param[in] fmt Format of data to be displayed
134 * @param[in] args Arguments to be displayed
136 #define LSP_LOG_fatal(fmt, arg...) do { \
137 LOGF(FONT_COLOR_BOLDRED"[%d]"fmt""FONT_COLOR_RESET,LSP_LOG_gettid(), ##arg); \
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
145 #define LSP_LOG_debug_func(fmt, arg...) do { \
146 LOGD(FONT_COLOR_CYAN"[%d]"fmt""FONT_COLOR_RESET, LSP_LOG_gettid(), ##arg); \
151 #endif /* __cplusplus */
153 #endif /* __LIB_SERVICE_PLUGIN_LOG_H__ */