1 /**************************************************************************
5 * Copyright 2015 Samsung Electronics co., Ltd. All Rights Reserved.
7 * Contact: Eunchul Kim <chulspro.kim@samsung.com>,
8 * JinYoung Jeon <jy0.jeon@samsung.com>,
9 * Taeheon Kim <th908.kim@samsung.com>,
10 * YoungJun Cho <yj44.cho@samsung.com>,
11 * SooChan Lim <sc1.lim@samsung.com>,
12 * Boram Park <sc1.lim@samsung.com>
14 * Permission is hereby granted, free of charge, to any person obtaining a
15 * copy of this software and associated documentation files (the
16 * "Software"), to deal in the Software without restriction, including
17 * without limitation the rights to use, copy, modify, merge, publish,
18 * distribute, sub license, and/or sell copies of the Software, and to
19 * permit persons to whom the Software is furnished to do so, subject to
20 * the following conditions:
22 * The above copyright notice and this permission notice (including the
23 * next paragraph) shall be included in all copies or substantial portions
26 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
27 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
28 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
29 * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
30 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
31 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
32 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
34 **************************************************************************/
44 #include <sys/syscall.h>
49 #include "tdm_macro.h"
51 //#define TDM_CONFIG_ASSERT
53 #define LOG_MAX_LEN 4076
55 #define COLOR_RED "\x1b[31m" /* for error */
56 #define COLOR_YELLOW "\x1b[33m" /* for warning */
57 #define COLOR_GREEN "\x1b[32m" /* for info */
58 #define COLOR_RESET "\x1b[0m"
63 static unsigned int dlog_enable;
64 static unsigned int color_enable = 1;
65 static unsigned int debug_level = TDM_LOG_LEVEL_INFO;
67 static unsigned int need_check_env = 1;
70 _tdm_log_check_env(void)
75 str = getenv("TDM_DEBUG_LEVEL");
77 debug_level = strtol(str, &end, 10);
79 str = getenv("TDM_DEBUG");
80 if (str && (strstr(str, "1")))
81 debug_level = TDM_LOG_LEVEL_DBG;
83 str = getenv("TDM_DLOG");
84 if (str && (strstr(str, "1")))
89 tdm_log_enable_color(unsigned int enable)
91 color_enable = enable;
95 tdm_log_enable_dlog(unsigned int enable)
101 tdm_log_enable_debug(unsigned int enable)
104 debug_level = TDM_LOG_LEVEL_DBG;
106 debug_level = TDM_LOG_LEVEL_INFO;
110 tdm_log_set_debug_level(int level)
116 tdm_log_print(int level, const char *fmt, ...)
120 if (need_check_env) {
122 _tdm_log_check_env();
125 if (level > debug_level)
129 log_priority dlog_prio;
131 case TDM_LOG_LEVEL_ERR:
132 dlog_prio = DLOG_ERROR;
134 case TDM_LOG_LEVEL_WRN:
135 dlog_prio = DLOG_WARN;
137 case TDM_LOG_LEVEL_INFO:
138 dlog_prio = DLOG_INFO;
140 case TDM_LOG_LEVEL_DBG:
141 dlog_prio = DLOG_DEBUG;
147 dlog_vprint(dlog_prio, LOG_TAG, fmt, arg);
151 char *lvl_str[] = {"TDM_NON", "TDM_ERR", "TDM_WRN", "TDM_INF", "TDM_DBG"};
152 char *color[] = {COLOR_RESET, COLOR_RED, COLOR_YELLOW, COLOR_GREEN, COLOR_RESET};
154 clock_gettime(CLOCK_MONOTONIC, &ts);
157 printf("%s", color[level]);
158 printf("[%s]", lvl_str[level]);
161 printf("[%d.%06d]", (int)ts.tv_sec, (int)ts.tv_nsec / 1000);
167 #ifdef TDM_CONFIG_ASSERT