From 584df55c7381adf84f2f4f91982402a497d91e04 Mon Sep 17 00:00:00 2001 From: Doyoun Kang Date: Sun, 9 Aug 2020 14:28:19 +0900 Subject: [PATCH] DSDebug: add code to print line number Change-Id: Ibbdb6852f991727712183a9dcb07ad72a5e9661c --- src/DSDebug/DSDebugLog.cpp | 4 ++-- src/DSDebug/DSDebugLog.h | 10 +++++----- tests/DSDebugLog-test.cpp | 8 ++++---- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/DSDebug/DSDebugLog.cpp b/src/DSDebug/DSDebugLog.cpp index 877eb89..730a9ec 100644 --- a/src/DSDebug/DSDebugLog.cpp +++ b/src/DSDebug/DSDebugLog.cpp @@ -31,7 +31,7 @@ DSDebugLog *DSDebugLog::GetInstance() return mInstance; } -void DSDebugLog::printLog(int logLevel, const char *funcName, const char *fmt, ...) +void DSDebugLog::printLog(int logLevel, const char *funcName, int line, const char *fmt, ...) { //TODO: apply logLevel //TODO: use dlog or stdout @@ -43,7 +43,7 @@ void DSDebugLog::printLog(int logLevel, const char *funcName, const char *fmt, . va_start(arg, fmt); printf("%s", color[logLevel]); printf("[%s]", lvl_str[logLevel]); - printf(":[%s]", funcName); + 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 775130f..33c19b5 100644 --- a/src/DSDebug/DSDebugLog.h +++ b/src/DSDebug/DSDebugLog.h @@ -22,7 +22,7 @@ public: void operator=(const DSDebugLog &) = delete; // should not be assignable static DSDebugLog *GetInstance(); - void printLog(int logLevel, const char *funcName, const char *fmt, ...); + void printLog(int logLevel, const char *funcName, int line, const char *fmt, ...); int getLogLevel(); private: @@ -37,28 +37,28 @@ private: #define DSLOG_DBG(domain, fmt, args...) \ do { \ DSDebugLog *log = DSDebugLog::GetInstance(); \ - log->printLog(DSDebugLog::LOG_LEVEL_DEBUG, __func__, "[" domain "]: " fmt, \ + log->printLog(DSDebugLog::LOG_LEVEL_DEBUG, __func__, __LINE__, "[" domain "]: " fmt, \ ##args); \ } while (0) #define DSLOG_INF(domain, fmt, args...) \ do { \ DSDebugLog *log = DSDebugLog::GetInstance(); \ - log->printLog(DSDebugLog::LOG_LEVEL_INFO, __func__, "[" domain "]: " fmt, \ + log->printLog(DSDebugLog::LOG_LEVEL_INFO, __func__, __LINE__, "[" domain "]: " fmt, \ ##args); \ } while (0) #define DSLOG_WRN(domain, fmt, args...) \ do { \ DSDebugLog *log = DSDebugLog::GetInstance(); \ - log->printLog(DSDebugLog::LOG_LEVEL_WARN, __func__, "[" domain "]: " fmt, \ + log->printLog(DSDebugLog::LOG_LEVEL_WARN, __func__, __LINE__, "[" domain "]: " fmt, \ ##args); \ } while (0) #define DSLOG_ERR(domain, fmt, args...) \ do { \ DSDebugLog *log = DSDebugLog::GetInstance(); \ - log->printLog(DSDebugLog::LOG_LEVEL_ERR, __func__, "[" domain "]: " fmt, \ + log->printLog(DSDebugLog::LOG_LEVEL_ERR, __func__, __LINE__, "[" domain "]: " fmt, \ ##args); \ } while (0) } diff --git a/tests/DSDebugLog-test.cpp b/tests/DSDebugLog-test.cpp index b86456d..d4757f4 100644 --- a/tests/DSDebugLog-test.cpp +++ b/tests/DSDebugLog-test.cpp @@ -23,10 +23,10 @@ TEST_F(DSDebugLogTest, PrintLog) const char *str = "Hi world"; DSDebugLog *log = DSDebugLog::GetInstance(); - log->printLog(DSDebugLog::LOG_LEVEL_DEBUG, __func__, "Hello world"); - log->printLog(DSDebugLog::LOG_LEVEL_INFO, __func__, "%s", str); - log->printLog(DSDebugLog::LOG_LEVEL_WARN, __func__, "Greeting world"); - log->printLog(DSDebugLog::LOG_LEVEL_ERR, __func__, "Hey world"); + 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"); EXPECT_TRUE(true); } -- 2.7.4