DSDebug: check environment to use dlog 12/242312/1
authorjeon <jhyuni.kang@samsung.com>
Mon, 24 Aug 2020 11:41:59 +0000 (20:41 +0900)
committerSung-Jin Park <sj76.park@samsung.com>
Tue, 25 Aug 2020 12:36:19 +0000 (21:36 +0900)
Change-Id: I3d98a8723c33ca96b80bb503a40d21c88b3c12c4

src/DSDebug/DSDebugLog.cpp
src/DSDebug/DSDebugLog.h

index 2900668..3966335 100644 (file)
@@ -24,6 +24,7 @@
 #include <stdio.h>
 #include <stdarg.h>
 #include "DSDebugLog.h"
+#include <dlog.h>
 
 #define COLOR_RED "\x1b[31m" /* for error */
 #define COLOR_YELLOW "\x1b[33m" /* for warning */
 namespace display_server
 {
 DSDebugLog::DSDebugLog() : mLogLevel(LOG_LEVEL_DEBUG)
-{}
+{
+       char *tmp = getenv("DSLOG_DLOG_ENABLE");
+       char *env = strdup(tmp);
+       int value = atoi(env);
+
+       free(env);
+
+       if (value == 1)
+               __enableDlog = true;
+       else
+               __enableDlog = false;
+}
 
 DSDebugLog::~DSDebugLog()
 {}
@@ -59,17 +71,32 @@ void DSDebugLog::printLog(int logLevel, const char *domain, const char *funcName
        //TODO: use dlog or stdout
        //TODO: use dlog filters
        va_list arg;
-       const char *lvl_str[] = { "DS_DBG", "DS_INF", "DS_WRN", "DS_ERR" };
-       const char *color[] = { COLOR_RESET, COLOR_GREEN, COLOR_YELLOW, COLOR_RED };
-
-       va_start(arg, fmt);
-       printf("%s", color[logLevel]);
-       printf("[%s]", lvl_str[logLevel]);
-       printf("[%s]", domain);
-       printf(":[%s(%d)]:", funcName, line);
-       vprintf(fmt, arg);
-       printf("\n");
-       va_end(arg);
+
+       if (__enableDlog)
+       {
+               const log_priority dlogLevel[] = { DLOG_DEBUG, DLOG_INFO, DLOG_WARN, DLOG_ERROR };
+               char buf[512] = {0,};
+
+               va_start(arg, fmt);
+               vsnprintf((char *)buf, sizeof(buf), fmt, arg);
+               va_end(arg);
+
+               dlog_print(dlogLevel[logLevel], "LIBDS", "[%s][%s:%d] %s", domain, funcName, line, buf);
+       }
+       else
+       {
+               const char *lvl_str[] = { "DS_DBG", "DS_INF", "DS_WRN", "DS_ERR" };
+               const char *color[] = { COLOR_RESET, COLOR_GREEN, COLOR_YELLOW, COLOR_RED };
+
+               va_start(arg, fmt);
+               printf( "%s", color[logLevel]);
+               printf( "[%s]", lvl_str[logLevel]);
+               printf( "[%s]", domain);
+               printf( ":[%s(%d)]:", funcName, line);
+               vprintf( fmt, arg);
+               printf( "\n");
+               va_end(arg);
+       }
 }
 
 int DSDebugLog::getLogLevel()
index 12be42e..a1e8dfd 100644 (file)
@@ -55,6 +55,7 @@ private:
        static DSDebugLog *mInstance; // singleton instance
        static std::mutex mMutex; // mutex
        int mLogLevel; // current log level
+       bool __enableDlog;
 };
 
 #define DSLOG_DBG(domain, fmt, args...)                                  \