log: check log level
[platform/core/uifw/libtdm.git] / include / tdm_log.h
index d402a99..1cab32d 100644 (file)
@@ -70,37 +70,47 @@ void tdm_log_enable_debug(unsigned int enable);
 void tdm_log_set_debug_level(int level);
 void tdm_log_print(int level, const char *fmt, ...);
 
+extern unsigned int tdm_log_debug_level;
+
 #define TDM_DBG(fmt, args...) \
        do { \
-               struct timespec ts; \
-               clock_gettime(CLOCK_MONOTONIC, &ts); \
-               tdm_log_print(TDM_LOG_LEVEL_DBG, "[%5d.%06d][%d][%s %d]"fmt"\n", \
-                                         (int)ts.tv_sec, (int)ts.tv_nsec / 1000, \
-                                         (int)syscall(SYS_gettid), __FUNCTION__, __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"\n", \
+                                                 (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); \
-               tdm_log_print(TDM_LOG_LEVEL_INFO, "[%5d.%06d][%d][%s %d]"fmt"\n", \
-                                         (int)ts.tv_sec, (int)ts.tv_nsec / 1000, \
-                                         (int)syscall(SYS_gettid), __FUNCTION__, __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"\n", \
+                                                 (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); \
-               tdm_log_print(TDM_LOG_LEVEL_WRN, "[%5d.%06d][%d][%s %d]"fmt"\n", \
-                                         (int)ts.tv_sec, (int)ts.tv_nsec / 1000, \
-                                         (int)syscall(SYS_gettid), __FUNCTION__, __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"\n", \
+                                                 (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); \
-               tdm_log_print(TDM_LOG_LEVEL_ERR, "[%5d.%06d][%d][%s %d]"fmt"\n", \
-                                         (int)ts.tv_sec, (int)ts.tv_nsec / 1000, \
-                                         (int)syscall(SYS_gettid), __FUNCTION__, __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"\n", \
+                                                 (int)ts.tv_sec, (int)ts.tv_nsec / 1000, \
+                                                 (int)syscall(SYS_gettid), __FUNCTION__, __LINE__, ##args);  \
+               } \
        } while (0)
 
 #ifdef __cplusplus