DSDebug: add code to print line number 64/241764/1
authorDoyoun Kang <doyoun.kang@samsung.com>
Sun, 9 Aug 2020 05:28:19 +0000 (14:28 +0900)
committerSung-Jin Park <sj76.park@samsung.com>
Thu, 20 Aug 2020 10:10:21 +0000 (19:10 +0900)
Change-Id: Ibbdb6852f991727712183a9dcb07ad72a5e9661c

src/DSDebug/DSDebugLog.cpp
src/DSDebug/DSDebugLog.h
tests/DSDebugLog-test.cpp

index 877eb89..730a9ec 100644 (file)
@@ -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);
index 775130f..33c19b5 100644 (file)
@@ -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)
 }
index b86456d..d4757f4 100644 (file)
@@ -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);
 }