log: enable dlog by default to debug client error
[platform/core/uifw/libtdm.git] / common / tdm_log.c
index 5e1ab2c..593dc5e 100644 (file)
@@ -43,6 +43,7 @@
 #include <assert.h>
 #include <sys/syscall.h>
 #include <dlog.h>
+#include <pthread.h>
 
 #include "tdm.h"
 #include "tdm_log.h"
 #undef LOG_TAG
 #define LOG_TAG "TDM"
 
-static unsigned int dlog_enable;
+static unsigned int dlog_enable = 1;
 static unsigned int color_enable = 1;
 static unsigned int debug_level = TDM_LOG_LEVEL_INFO;
 
 static unsigned int need_check_env = 1;
 
+static unsigned int log_lock_init;
+static pthread_mutex_t log_lock;
+
 static void
 _tdm_log_check_env(void)
 {
@@ -81,8 +85,8 @@ _tdm_log_check_env(void)
                debug_level = TDM_LOG_LEVEL_DBG;
 
        str = getenv("TDM_DLOG");
-       if (str && (strstr(str, "1")))
-               dlog_enable = 1;
+       if (str && (strstr(str, "0")))
+               dlog_enable = 0;
 }
 
 EXTERN void
@@ -117,6 +121,12 @@ tdm_log_print(int level, const char *fmt, ...)
 {
        va_list arg;
 
+       if (!log_lock_init) {
+               log_lock_init = 1;
+               pthread_mutex_init(&log_lock, NULL);
+
+       }
+
        if (need_check_env) {
                need_check_env = 0;
                _tdm_log_check_env();
@@ -153,6 +163,8 @@ tdm_log_print(int level, const char *fmt, ...)
 
                clock_gettime(CLOCK_MONOTONIC, &ts);
 
+               pthread_mutex_lock(&log_lock);
+
                if (color_enable)
                        printf("%s", color[level]);
                printf("[%s]", lvl_str[level]);
@@ -162,6 +174,8 @@ tdm_log_print(int level, const char *fmt, ...)
                va_start(arg, fmt);
                vprintf(fmt, arg);
                va_end(arg);
+
+               pthread_mutex_unlock(&log_lock);
        }
 
 #ifdef TDM_CONFIG_ASSERT