From 107f8833b394b92678dfc76bb78cb6e0aa762fa4 Mon Sep 17 00:00:00 2001 From: Sung-Jin Park Date: Mon, 16 Sep 2019 20:47:22 +0900 Subject: [PATCH] PUI: set log level from env variable, update some log messages Change-Id: I3d9c10bd213839c25499f0f654157ad25d1d491d Signed-off-by: Sung-Jin Park --- include/PUI_common.h | 25 ++++++++++++++++++------- src/PUI.c | 19 +++++++++++++++---- 2 files changed, 33 insertions(+), 11 deletions(-) diff --git a/include/PUI_common.h b/include/PUI_common.h index b5c5738..d937115 100644 --- a/include/PUI_common.h +++ b/include/PUI_common.h @@ -26,6 +26,8 @@ #ifndef _LIBPUI_COMMON_H_ #define _LIBPUI_COMMON_H_ +int _pui_log_level; + typedef enum { PUI_ERROR_NONE, PUI_ERROR_INVALID_ANI_HANDLE, @@ -68,6 +70,12 @@ typedef enum { PUI_INT_ERROR_UNKNOWN, } pui_int_error; +typedef enum { + PUI_LOG_LEVEL_INFO, + PUI_LOG_LEVEL_DEBUG, + PUI_LOG_LEVEL_ERROR, +} pui_log_level; + typedef unsigned int pui_bool; typedef char* pui_id; typedef char* pui_error_string; @@ -91,18 +99,21 @@ struct _pui_ani_control_buffer }; #define pui_err(msg, ...) \ - do { \ - fprintf(stderr, "[ERROR][%s][%d] " msg, __FUNCTION__, __LINE__, ##__VA_ARGS__); \ + do { \ + if (_pui_log_level <= PUI_LOG_LEVEL_ERROR) \ + fprintf(stderr, "[ERROR][%s][%d] " msg, __FUNCTION__, __LINE__, ##__VA_ARGS__); \ } while(0) -#define pui_warn(msg, ...) \ - do { \ - fprintf(stderr, "[WARNING][%s][%d] " msg, __FUNCTION__, __LINE__, ##__VA_ARGS__); \ +#define pui_debug(msg, ...) \ + do { \ + if (_pui_log_level <= PUI_LOG_LEVEL_DEBUG) \ + fprintf(stdout, "[DEBUG][%s][%d] " msg, __FUNCTION__, __LINE__, ##__VA_ARGS__); \ } while(0) #define pui_info(msg, ...) \ - do { \ - fprintf(stdout, "[INFO][%s][%d] " msg, __FUNCTION__, __LINE__, ##__VA_ARGS__); \ + do { \ + if (_pui_log_level <= PUI_LOG_LEVEL_INFO) \ + fprintf(stdout, "[INFO][%s][%d] " msg, __FUNCTION__, __LINE__, ##__VA_ARGS__); \ } while(0) #endif//_LIBPUI_COMMON_H_ diff --git a/src/PUI.c b/src/PUI.c index cf0d35b..2da36b2 100644 --- a/src/PUI.c +++ b/src/PUI.c @@ -117,12 +117,12 @@ pui_display_get_buffer(pui_h handle) if (handle->current_surface) { - pui_warn("Current_surface is not used !\n"); + pui_debug("[GET BUFFER] Current_surface is not used !\n"); } if (!tbm_surface_queue_can_dequeue(handle->tbm_queue, 0)) { - pui_err("Failed to dequeue a tbm_surface !\n"); + pui_err("[GET BUFFER] Failed to dequeue a tbm_surface !\n"); return NULL; } @@ -130,7 +130,7 @@ pui_display_get_buffer(pui_h handle) if (ret != TBM_SURFACE_ERROR_NONE) { - pui_err("[UPDATE] dequeue err:%d\n", ret); + pui_err("[GET BUFFER] Dequeue err:%d\n", ret); return NULL; } @@ -183,7 +183,7 @@ pui_display_update(pui_h handle) if (!handle->is_buffer_set) { - pui_err("Buffer is not set !\n"); + pui_err("[UPDATE] Buffer is not set !\n"); return PUI_ERROR_INVALID_BUFFER; } @@ -548,9 +548,20 @@ _pui_event_shutdown(void) int pui_init(void) { + const char *cp = NULL; + if (++_pui_init_count != 1) return _pui_init_count; + _pui_log_level = PUI_LOG_LEVEL_DEBUG; + + cp = getenv("LIBPUI_LOG_LEVEL"); + + if (cp) + { + _pui_log_level = atoi(cp); + } + if (pui_module) { pui_err("Invalid calling of pui_init() !\n"); -- 2.7.4