erase unreachable code
[platform/core/uifw/libtdm.git] / include / tdm_log.h
index c55acf6..de56386 100644 (file)
@@ -9,7 +9,7 @@
  *          Taeheon Kim <th908.kim@samsung.com>,
  *          YoungJun Cho <yj44.cho@samsung.com>,
  *          SooChan Lim <sc1.lim@samsung.com>,
- *          Boram Park <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
 #ifndef _TDM_LOG_H_
 #define _TDM_LOG_H_
 
+#include <unistd.h>
+#include <sys/syscall.h>
+#include <time.h>
 
 #ifdef __cplusplus
 extern "C" {
 #endif
 
-#include <unistd.h>
-#include <time.h>
-#include <assert.h>
-#include <sys/syscall.h>
-
-
 /**
  * @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
+ * 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
  */
-extern int tdm_debug;
 
-//#define TDM_CONFIG_DLOG
-//#define TDM_CONFIG_ASSERT
-
-#undef TDM_ASSERT
-#ifdef TDM_CONFIG_ASSERT
-#define TDM_ASSERT(o) assert(o)
-#else
-#define TDM_ASSERT(o)
-#endif
-
-#ifdef TDM_CONFIG_DLOG
-
-#include <dlog.h>
-
-#ifdef LOG_TAG
-#undef LOG_TAG
-#endif
-#define LOG_TAG "TDM"
+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...) \
        do { \
-               if (tdm_debug) { \
-                       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][%d][%s %d] "fmt"\n", (int)ts.tv_sec, \
-                               (int)ts.tv_nsec / 1000, (int)syscall(SYS_gettid), __func__, __LINE__, ##args); \
+               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...) \
        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][%d][%s %d] "fmt"\n", (int)ts.tv_sec, \
-                       (int)ts.tv_nsec / 1000, (int)syscall(SYS_gettid), __func__, __LINE__, ##args); \
+               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...) \
        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][%d][%s %d] "fmt"\n", (int)ts.tv_sec, \
-                       (int)ts.tv_nsec / 1000, (int)syscall(SYS_gettid), __func__, __LINE__, ##args); \
+               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...) \
        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][%d][%s %d] "fmt"\n", (int)ts.tv_sec, \
-                       (int)ts.tv_nsec / 1000, (int)syscall(SYS_gettid), __func__, __LINE__, ##args); \
-       } while (0)
-
-#else /* TDM_CONFIG_DLOG */
-
-#include <stdio.h>
-
-#define COLOR_RED "\x1b[31m"      /* for error */
-#define COLOR_YELLOW "\x1b[33m"   /* for warning */
-#define COLOR_GREEN "\x1b[32m"    /* for info */
-#define COLOR_RESET "\x1b[0m"
-
-#define TDM_DBG(fmt, args...) \
-       do { \
-               if (tdm_debug) { \
-                       struct timespec ts;     \
-                       clock_gettime(CLOCK_MONOTONIC, &ts);    \
-                       printf("[TDM_DBG][%d.%06d][%d][%s %d] "fmt"\n", (int)ts.tv_sec, \
-                               (int)ts.tv_nsec / 1000, (int)syscall(SYS_gettid), __func__, __LINE__, ##args); \
+               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_INFO(fmt, args...) \
-       do { \
-               struct timespec ts;     \
-               clock_gettime(CLOCK_MONOTONIC, &ts);    \
-               printf(COLOR_GREEN"[TDM_INF]"COLOR_RESET"[%d.%06d][%d][%s %d] "fmt"\n", (int)ts.tv_sec, \
-                       (int)ts.tv_nsec / 1000, (int)syscall(SYS_gettid), __func__, __LINE__, ##args); \
-       } while (0)
-
-#define TDM_WRN(fmt, args...) \
+#define TDM_NEVER_GET_HERE() TDM_WRN("** NEVER GET HERE **")
+#define TDM_DEPRECATED(str) \
        do { \
-               struct timespec ts;     \
-               clock_gettime(CLOCK_MONOTONIC, &ts);    \
-               printf(COLOR_YELLOW"[TDM_WRN]"COLOR_RESET"[%d.%06d][%d][%s %d] "fmt"\n", (int)ts.tv_sec,        \
-                       (int)ts.tv_nsec / 1000, (int)syscall(SYS_gettid), __func__, __LINE__, ##args); \
-               TDM_ASSERT(0); \
-       } while (0)
-
-#define TDM_ERR(fmt, args...) \
-       do { \
-               struct timespec ts;     \
-               clock_gettime(CLOCK_MONOTONIC, &ts);    \
-               printf(COLOR_RED"[TDM_ERR]"COLOR_RESET"[%d.%06d][%d][%s %d] "fmt"\n", (int)ts.tv_sec,   \
-                       (int)ts.tv_nsec / 1000, (int)syscall(SYS_gettid), __func__, __LINE__, ##args); \
-               TDM_ASSERT(0); \
-       } while (0)
-
-#endif /* TDM_CONFIG_DLOG */
+               if (str) \
+                       TDM_WRN("** DEPRECATED: %s **", str); \
+               else \
+                       TDM_WRN("** DEPRECATED **"); \
+       } while(0)
 
 #ifdef __cplusplus
 }