#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()
{}
//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()