#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 debug_enable;
+static unsigned int dlog_enable = 1;
+static unsigned int color_enable = 1;
static unsigned int need_check_env = 1;
+static unsigned int log_lock_init;
+static pthread_mutex_t log_lock;
+
+unsigned int tdm_log_debug_level = TDM_LOG_LEVEL_INFO;
+
static void
_tdm_log_check_env(void)
{
const char *str;
+ char *end;
+
+ str = getenv("TDM_DEBUG_LEVEL");
+ if (str)
+ tdm_log_debug_level = strtol(str, &end, 10);
str = getenv("TDM_DEBUG");
if (str && (strstr(str, "1")))
- debug_enable = 1;
+ tdm_log_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
+tdm_log_enable_color(unsigned int enable)
+{
+ color_enable = enable;
}
EXTERN void
EXTERN void
tdm_log_enable_debug(unsigned int enable)
{
- debug_enable = enable;
+ if (enable)
+ tdm_log_debug_level = TDM_LOG_LEVEL_DBG;
+ else
+ tdm_log_debug_level = TDM_LOG_LEVEL_INFO;
+}
+
+EXTERN void
+tdm_log_set_debug_level(int level)
+{
+ tdm_log_debug_level = level;
}
EXTERN void
{
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();
}
- if (level > 3 && !debug_enable)
+ if (level > tdm_log_debug_level)
return;
if (dlog_enable) {
return;
}
va_start(arg, fmt);
- dlog_vprint(dlog_prio, LOG_TAG, fmt, arg);
+ __dlog_vprint(LOG_ID_SYSTEM, dlog_prio, LOG_TAG, fmt, arg);
va_end(arg);
} else {
struct timespec ts;
clock_gettime(CLOCK_MONOTONIC, &ts);
- printf("%s", color[level]);
+ pthread_mutex_lock(&log_lock);
+
+ if (color_enable)
+ printf("%s", color[level]);
printf("[%s]", lvl_str[level]);
- printf(COLOR_RESET"[%d.%06d]", (int)ts.tv_sec, (int)ts.tv_nsec / 1000);
+ if (color_enable)
+ printf(COLOR_RESET);
+ printf("[%d.%06d]", (int)ts.tv_sec, (int)ts.tv_nsec / 1000);
va_start(arg, fmt);
vprintf(fmt, arg);
va_end(arg);
+
+ pthread_mutex_unlock(&log_lock);
}
#ifdef TDM_CONFIG_ASSERT