From 174dde585e9e9ad3f34af6160371c70e06ce090e Mon Sep 17 00:00:00 2001 From: Boram Park Date: Wed, 7 Mar 2018 10:18:07 +0900 Subject: [PATCH] log: add tdm_log_print_stdout Change-Id: I9ee3b16818e868f75b7bb114182f293d94a278bc --- common/tdm_log.c | 54 ++++++++++++++++++++++++++++++++++++------------------ include/tdm_log.h | 2 ++ 2 files changed, 38 insertions(+), 18 deletions(-) diff --git a/common/tdm_log.c b/common/tdm_log.c index aa3d182..348ea99 100644 --- a/common/tdm_log.c +++ b/common/tdm_log.c @@ -147,20 +147,50 @@ tdm_log_set_path(const char *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_print_stdout(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) { @@ -183,21 +213,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); diff --git a/include/tdm_log.h b/include/tdm_log.h index 5a9fb65..e25f685 100644 --- a/include/tdm_log.h +++ b/include/tdm_log.h @@ -69,7 +69,9 @@ 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_print_stdout(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; -- 2.7.4