From d2491aec3a18af12ebfb2622704a15f9f700d5fb Mon Sep 17 00:00:00 2001 From: Sung-Jin Park Date: Thu, 20 Aug 2020 14:58:40 +0900 Subject: [PATCH] DSDebug: fix to print 'domain' before the funtion name Change-Id: I1fcfdad9d29980c7017e02bd067dba32cd7b9fbe Signed-off-by: Sung-Jin Park --- src/DSDebug/DSDebugLog.cpp | 5 +++-- src/DSDebug/DSDebugLog.h | 10 +++++----- tests/DSDebugLog-test.cpp | 8 ++++---- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/DSDebug/DSDebugLog.cpp b/src/DSDebug/DSDebugLog.cpp index fd15355..2900668 100644 --- a/src/DSDebug/DSDebugLog.cpp +++ b/src/DSDebug/DSDebugLog.cpp @@ -53,7 +53,7 @@ DSDebugLog *DSDebugLog::GetInstance() return mInstance; } -void DSDebugLog::printLog(int logLevel, const char *funcName, int line, const char *fmt, ...) +void DSDebugLog::printLog(int logLevel, const char *domain, const char *funcName, int line, const char *fmt, ...) { //TODO: apply logLevel //TODO: use dlog or stdout @@ -65,7 +65,8 @@ void DSDebugLog::printLog(int logLevel, const char *funcName, int line, const ch va_start(arg, fmt); printf("%s", color[logLevel]); printf("[%s]", lvl_str[logLevel]); - printf(":[%s(%d)]", funcName, line); + printf("[%s]", domain); + printf(":[%s(%d)]:", funcName, line); vprintf(fmt, arg); printf("\n"); va_end(arg); diff --git a/src/DSDebug/DSDebugLog.h b/src/DSDebug/DSDebugLog.h index d9a3dad..12be42e 100644 --- a/src/DSDebug/DSDebugLog.h +++ b/src/DSDebug/DSDebugLog.h @@ -45,7 +45,7 @@ public: void operator=(const DSDebugLog &) = delete; // should not be assignable static DSDebugLog *GetInstance(); - void printLog(int logLevel, const char *funcName, int line, const char *fmt, ...); + void printLog(int logLevel, const char *domain, const char *funcName, int line, const char *fmt, ...); int getLogLevel(); private: @@ -60,28 +60,28 @@ private: #define DSLOG_DBG(domain, fmt, args...) \ do { \ DSDebugLog *log = DSDebugLog::GetInstance(); \ - log->printLog(DSDebugLog::LOG_LEVEL_DEBUG, __func__, __LINE__, "[" domain "]: " fmt, \ + log->printLog(DSDebugLog::LOG_LEVEL_DEBUG, domain, __func__, __LINE__, fmt, \ ##args); \ } while (0) #define DSLOG_INF(domain, fmt, args...) \ do { \ DSDebugLog *log = DSDebugLog::GetInstance(); \ - log->printLog(DSDebugLog::LOG_LEVEL_INFO, __func__, __LINE__, "[" domain "]: " fmt, \ + log->printLog(DSDebugLog::LOG_LEVEL_INFO, domain, __func__, __LINE__, fmt, \ ##args); \ } while (0) #define DSLOG_WRN(domain, fmt, args...) \ do { \ DSDebugLog *log = DSDebugLog::GetInstance(); \ - log->printLog(DSDebugLog::LOG_LEVEL_WARN, __func__, __LINE__, "[" domain "]: " fmt, \ + log->printLog(DSDebugLog::LOG_LEVEL_WARN, domain, __func__, __LINE__, fmt, \ ##args); \ } while (0) #define DSLOG_ERR(domain, fmt, args...) \ do { \ DSDebugLog *log = DSDebugLog::GetInstance(); \ - log->printLog(DSDebugLog::LOG_LEVEL_ERR, __func__, __LINE__, "[" domain "]: " fmt, \ + log->printLog(DSDebugLog::LOG_LEVEL_ERR, domain, __func__, __LINE__, fmt, \ ##args); \ } while (0) } diff --git a/tests/DSDebugLog-test.cpp b/tests/DSDebugLog-test.cpp index 71265ed..78322b4 100644 --- a/tests/DSDebugLog-test.cpp +++ b/tests/DSDebugLog-test.cpp @@ -46,10 +46,10 @@ TEST_F(DSDebugLogTest, PrintLog) const char *str = "Hi world"; DSDebugLog *log = DSDebugLog::GetInstance(); - log->printLog(DSDebugLog::LOG_LEVEL_DEBUG, __func__, __LINE__, "Hello world"); - log->printLog(DSDebugLog::LOG_LEVEL_INFO, __func__, __LINE__, "%s", str); - log->printLog(DSDebugLog::LOG_LEVEL_WARN, __func__, __LINE__, "Greeting world"); - log->printLog(DSDebugLog::LOG_LEVEL_ERR, __func__, __LINE__, "Hey world"); + log->printLog(DSDebugLog::LOG_LEVEL_DEBUG, "DSDebugLogTest", __func__, __LINE__, "Hello world"); + log->printLog(DSDebugLog::LOG_LEVEL_INFO, "DSDebugLogTest", __func__, __LINE__, "%s", str); + log->printLog(DSDebugLog::LOG_LEVEL_WARN, "DSDebugLogTest", __func__, __LINE__, "Greeting world"); + log->printLog(DSDebugLog::LOG_LEVEL_ERR, "DSDebugLogTest", __func__, __LINE__, "Hey world"); EXPECT_TRUE(true); } -- 2.7.4