Package version up to 2.7.1
[platform/core/uifw/libtdm.git] / common / tdm_log.c
index e2d0277..975eb19 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
@@ -59,7 +59,7 @@
 #undef LOG_TAG
 #define LOG_TAG "TDM"
 
-static unsigned int dlog_enable = 0;
+static unsigned int dlog_enable = 1;
 static unsigned int color_enable = 1;
 
 static unsigned int assert_level = TDM_LOG_LEVEL_NONE;
@@ -75,42 +75,35 @@ EXTERN void
 tdm_log_enable_color(unsigned int enable)
 {
        color_enable = enable;
+       TDM_INFO("color_enable: %d", color_enable);
 }
 
 EXTERN void
 tdm_log_enable_dlog(unsigned int enable)
 {
-       const char *debug = getenv("TDM_DLOG");
-       if (debug && strstr(debug, "1"))
-               enable = 1;
-
        dlog_enable = enable;
-}
-
-EXTERN void
-tdm_log_enable_debug(unsigned int enable)
-{
-       if (enable)
-               tdm_log_debug_level = TDM_LOG_LEVEL_DBG;
-       else
-               tdm_log_debug_level = TDM_LOG_LEVEL_INFO;
+       TDM_INFO("dlog_enable: %d", dlog_enable);
 }
 
 EXTERN void
 tdm_log_set_debug_level(int level)
 {
        tdm_log_debug_level = level;
+       TDM_INFO("debug_level: %d", tdm_log_debug_level);
 }
 
 EXTERN void
 tdm_log_set_assert_level(int level)
 {
        assert_level = level;
+       TDM_INFO("assert_level: %d", assert_level);
 }
 
 EXTERN void
 tdm_log_set_path(const char *path)
 {
+       TDM_INFO("log_path: %s", path);
+
        if (!path) {
                if (stdout_fd != -1) {
                        fflush(stdout);
@@ -148,23 +141,54 @@ tdm_log_set_path(const char *path)
                close(STDOUT_FILENO);
                dup2(log_fd, STDOUT_FILENO);
                fclose(log_fl);
+               TDM_INFO("log_path: %s done", path);
        }
 }
 
-EXTERN void
-tdm_log_print(int level, const char *fmt, ...)
+static void
+_tdm_log_vprint_stdout(int level, const char *fmt, va_list ap)
 {
-       va_list arg;
-
        if (!log_lock_init) {
                log_lock_init = 1;
                pthread_mutex_init(&log_lock, NULL);
-
        }
 
        if (level > tdm_log_debug_level)
                return;
 
+       char *lvl_str[] = {"TDM_NON", "TDM_ERR", "TDM_WRN", "TDM_INF", "TDM_DBG"};
+       char *color[] = {COLOR_RESET, COLOR_RED, COLOR_YELLOW, COLOR_GREEN, COLOR_RESET};
+
+       pthread_mutex_lock(&log_lock);
+
+       if (color_enable)
+               printf("%s", color[level]);
+       printf("[%s]", lvl_str[level]);
+       if (color_enable)
+               printf(COLOR_RESET);
+       vprintf(fmt, ap);
+       printf("\n");
+       pthread_mutex_unlock(&log_lock);
+}
+
+
+EXTERN void
+tdm_log_printf(int level, const char *fmt, ...)
+{
+       va_list arg;
+       va_start(arg, fmt);
+       _tdm_log_vprint_stdout(level, fmt, arg);
+       va_end(arg);
+}
+
+EXTERN void
+tdm_log_print(int level, const char *fmt, ...)
+{
+       va_list arg;
+
+       if (level > tdm_log_debug_level)
+               return;
+
        if (dlog_enable) {
                log_priority dlog_prio;
                switch (level) {
@@ -187,21 +211,9 @@ tdm_log_print(int level, const char *fmt, ...)
                __dlog_vprint(LOG_ID_SYSTEM, dlog_prio, LOG_TAG, fmt, arg);
                va_end(arg);
        } else {
-               char *lvl_str[] = {"TDM_NON", "TDM_ERR", "TDM_WRN", "TDM_INF", "TDM_DBG"};
-               char *color[] = {COLOR_RESET, COLOR_RED, COLOR_YELLOW, COLOR_GREEN, COLOR_RESET};
-
-               pthread_mutex_lock(&log_lock);
-
-               if (color_enable)
-                       printf("%s", color[level]);
-               printf("[%s]", lvl_str[level]);
-               if (color_enable)
-                       printf(COLOR_RESET);
                va_start(arg, fmt);
-               vprintf(fmt, arg);
+               _tdm_log_vprint_stdout(level, fmt, arg);
                va_end(arg);
-               printf("\n");
-               pthread_mutex_unlock(&log_lock);
        }
 
        assert(level > assert_level);
@@ -210,6 +222,5 @@ tdm_log_print(int level, const char *fmt, ...)
 EXTERN void
 tdm_log_reset(void)
 {
-       pthread_mutex_trylock(&log_lock);
        pthread_mutex_unlock(&log_lock);
 }