PUI: set log level from env variable, update some log messages 07/220707/1
authorSung-Jin Park <sj76.park@samsung.com>
Mon, 16 Sep 2019 11:47:22 +0000 (20:47 +0900)
committerSung-Jin Park <sj76.park@samsung.com>
Fri, 20 Dec 2019 09:55:35 +0000 (18:55 +0900)
Change-Id: I3d9c10bd213839c25499f0f654157ad25d1d491d
Signed-off-by: Sung-Jin Park <sj76.park@samsung.com>
include/PUI_common.h
src/PUI.c

index b5c5738..d937115 100644 (file)
@@ -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_
index cf0d35b..2da36b2 100644 (file)
--- 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");