/**************************************************************************
-
-libtdm
-
-Copyright 2015 Samsung Electronics co., Ltd. All Rights Reserved.
-
-Contact: Eunchul Kim <chulspro.kim@samsung.com>,
- JinYoung Jeon <jy0.jeon@samsung.com>,
- Taeheon Kim <th908.kim@samsung.com>,
- YoungJun Cho <yj44.cho@samsung.com>,
- SooChan Lim <sc1.lim@samsung.com>,
- Boram Park <sc1.lim@samsung.com>
-
-Permission is hereby granted, free of charge, to any person obtaining a
-copy of this software and associated documentation files (the
-"Software"), to deal in the Software without restriction, including
-without limitation the rights to use, copy, modify, merge, publish,
-distribute, sub license, and/or sell copies of the Software, and to
-permit persons to whom the Software is furnished to do so, subject to
-the following conditions:
-
-The above copyright notice and this permission notice (including the
-next paragraph) shall be included in all copies or substantial portions
-of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
-OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
-IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
-ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
-TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
-SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-
+ *
+ * libtdm
+ *
+ * Copyright 2015 Samsung Electronics co., Ltd. All Rights Reserved.
+ *
+ * Contact: Eunchul Kim <chulspro.kim@samsung.com>,
+ * JinYoung Jeon <jy0.jeon@samsung.com>,
+ * Taeheon Kim <th908.kim@samsung.com>,
+ * YoungJun Cho <yj44.cho@samsung.com>,
+ * SooChan Lim <sc1.lim@samsung.com>,
+ * Boram Park <boram1288.park@samsung.com>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+ * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
+ * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
**************************************************************************/
#ifndef _TDM_LOG_H_
#define _TDM_LOG_H_
+#include <unistd.h>
+#include <sys/syscall.h>
+#include <time.h>
#ifdef __cplusplus
extern "C" {
#endif
-extern int tdm_debug;
-
-//#define TDM_CONFIG_DLOG
-#ifdef TDM_CONFIG_DLOG
-
-#include <dlog.h>
-#include <time.h>
-
-#ifdef LOG_TAG
-#undef LOG_TAG
-#endif
-#define LOG_TAG "TDM"
+/**
+ * @file tdm_log.h
+ * @brief The header file to print logs in frontend and backend modules
+ * @details
+ * The TDM debug log can be enable by setting "TDM_DEBUG" enviroment. And also,
+ * the TDM dlog can be enable by setting "TDM_DLOG" enviroment.
+ * @par Example
+ * @code
+ * $ export TDM_DEBUG=1
+ * @endcode
+ */
+
+enum {
+ TDM_LOG_LEVEL_NONE,
+ TDM_LOG_LEVEL_ERR,
+ TDM_LOG_LEVEL_WRN,
+ TDM_LOG_LEVEL_INFO,
+ TDM_LOG_LEVEL_DBG,
+};
+
+void tdm_log_enable_color(unsigned int enable);
+void tdm_log_enable_dlog(unsigned int enable);
+void tdm_log_set_debug_level(int level);
+void tdm_log_set_assert_level(int level);
+void tdm_log_set_path(const char *path);
+void tdm_log_printf(int level, const char *fmt, ...);
+void tdm_log_print(int level, const char *fmt, ...);
+void tdm_log_reset(void);
+
+extern unsigned int tdm_log_debug_level;
#define TDM_DBG(fmt, args...) \
- if (tdm_debug < 1) \
do { \
- struct timespec ts; \
- clock_gettime(CLOCK_MONOTONIC, &ts); \
- LOGD("[%d.%06d] "fmt"\n", (int)ts.tv_sec, (int)ts.tv_nsec / 1000, ##args); \
- printf("[TDM_DBG][%d.%06d][%s %d] "fmt"\n", (int)ts.tv_sec, \
- (int)ts.tv_nsec / 1000, __func__, __LINE__, ##args); \
- } while (0);
-
+ if (tdm_log_debug_level >= TDM_LOG_LEVEL_DBG) { \
+ struct timespec ts; \
+ clock_gettime(CLOCK_MONOTONIC, &ts); \
+ tdm_log_print(TDM_LOG_LEVEL_DBG, "[%5d.%06d][%d][%s %d]"fmt, \
+ (int)ts.tv_sec, (int)ts.tv_nsec / 1000, \
+ (int)syscall(SYS_gettid), __FUNCTION__, __LINE__, ##args); \
+ } \
+ } while (0)
#define TDM_INFO(fmt, args...) \
- if (tdm_debug < 2) \
do { \
- struct timespec ts; \
- clock_gettime(CLOCK_MONOTONIC, &ts); \
- LOGI("[%d.%06d] "fmt"\n", (int)ts.tv_sec, (int)ts.tv_nsec / 1000, ##args); \
- printf("[TDM_INF][%d.%06d][%s %d] "fmt"\n", (int)ts.tv_sec, \
- (int)ts.tv_nsec / 1000, __func__, __LINE__, ##args); \
- } while (0);
-
+ if (tdm_log_debug_level >= TDM_LOG_LEVEL_INFO) { \
+ struct timespec ts; \
+ clock_gettime(CLOCK_MONOTONIC, &ts); \
+ tdm_log_print(TDM_LOG_LEVEL_INFO, "[%5d.%06d][%d][%s %d]"fmt, \
+ (int)ts.tv_sec, (int)ts.tv_nsec / 1000, \
+ (int)syscall(SYS_gettid), __FUNCTION__, __LINE__, ##args); \
+ } \
+ } while (0)
#define TDM_WRN(fmt, args...) \
- if (tdm_debug < 3) \
do { \
- struct timespec ts; \
- clock_gettime(CLOCK_MONOTONIC, &ts); \
- LOGI("[%d.%06d] "fmt"\n", (int)ts.tv_sec, (int)ts.tv_nsec / 1000, ##args); \
- printf("[TDM_WRN][%d.%06d][%s %d] "fmt"\n", (int)ts.tv_sec, \
- (int)ts.tv_nsec / 1000, __func__, __LINE__, ##args); \
- } while (0);
-
+ if (tdm_log_debug_level >= TDM_LOG_LEVEL_WRN) { \
+ struct timespec ts; \
+ clock_gettime(CLOCK_MONOTONIC, &ts); \
+ tdm_log_print(TDM_LOG_LEVEL_WRN, "[%5d.%06d][%d][%s %d]"fmt, \
+ (int)ts.tv_sec, (int)ts.tv_nsec / 1000, \
+ (int)syscall(SYS_gettid), __FUNCTION__, __LINE__, ##args); \
+ } \
+ } while (0)
#define TDM_ERR(fmt, args...) \
- if (tdm_debug < 4) \
do { \
- struct timespec ts; \
- clock_gettime(CLOCK_MONOTONIC, &ts); \
- LOGE("[%d.%06d] "fmt"\n", (int)ts.tv_sec, (int)ts.tv_nsec / 1000, ##args); \
- printf("[TDM_ERR][%d.%06d][%s %d] "fmt"\n", (int)ts.tv_sec, \
- (int)ts.tv_nsec / 1000, __func__, __LINE__, ##args); \
- } while (0);
-
-#else /* TDM_CONFIG_DLOG */
-
-#include <stdio.h>
-#include <time.h>
-
-#define TDM_DBG(fmt, args...) \
- if (tdm_debug < 1) \
+ if (tdm_log_debug_level >= TDM_LOG_LEVEL_ERR) { \
+ struct timespec ts; \
+ clock_gettime(CLOCK_MONOTONIC, &ts); \
+ tdm_log_print(TDM_LOG_LEVEL_ERR, "[%5d.%06d][%d][%s %d]"fmt, \
+ (int)ts.tv_sec, (int)ts.tv_nsec / 1000, \
+ (int)syscall(SYS_gettid), __FUNCTION__, __LINE__, ##args); \
+ } \
+ } while (0)
+
+#define TDM_INIT_INFO(fmt, args...) \
do { \
- struct timespec ts; \
- clock_gettime(CLOCK_MONOTONIC, &ts); \
- printf("[TDM_DBG][%d.%06d][%s %d] "fmt"\n", (int)ts.tv_sec, \
- (int)ts.tv_nsec / 1000, __func__, __LINE__, ##args); \
- } while (0);
-
-#define TDM_INFO(fmt, args...) \
- if (tdm_debug < 2) \
+ if (tdm_log_debug_level >= TDM_LOG_LEVEL_INFO) { \
+ struct timespec ts; \
+ clock_gettime(CLOCK_MONOTONIC, &ts); \
+ tdm_log_print(TDM_LOG_LEVEL_INFO, "[%5d.%06d][%d][%s %d]"fmt, \
+ (int)ts.tv_sec, (int)ts.tv_nsec / 1000, \
+ (int)syscall(SYS_gettid), __FUNCTION__, __LINE__, ##args); \
+ } \
+ } while (0)
+
+#define TDM_NEVER_GET_HERE() TDM_WRN("** NEVER GET HERE **")
+#define TDM_DEPRECATED(str) \
do { \
- struct timespec ts; \
- clock_gettime(CLOCK_MONOTONIC, &ts); \
- printf("[TDM_INF][%d.%06d][%s %d] "fmt"\n", (int)ts.tv_sec, \
- (int)ts.tv_nsec / 1000, __func__, __LINE__, ##args); \
- } while (0);
-
-#define TDM_WRN(fmt, args...) \
- if (tdm_debug < 3) \
- do { \
- struct timespec ts; \
- clock_gettime(CLOCK_MONOTONIC, &ts); \
- printf("[TDM_WRN][%d.%06d][%s %d] "fmt"\n", (int)ts.tv_sec, \
- (int)ts.tv_nsec / 1000, __func__, __LINE__, ##args); \
- } while (0);
-
-#define TDM_ERR(fmt, args...) \
- if (tdm_debug < 4) \
- do { \
- struct timespec ts; \
- clock_gettime(CLOCK_MONOTONIC, &ts); \
- printf("[TDM_ERR][%d.%06d][%s %d] "fmt"\n", (int)ts.tv_sec, \
- (int)ts.tv_nsec / 1000, __func__, __LINE__, ##args); \
- } while (0);
-
-#endif /* TDM_CONFIG_DLOG */
+ if (str) \
+ TDM_WRN("** DEPRECATED: %s **", str); \
+ else \
+ TDM_WRN("** DEPRECATED **"); \
+ } while(0)
#ifdef __cplusplus
}