Optimize log message 64/26964/1
authorPiotr Bartosiewicz <p.bartosiewi@partner.samsung.com>
Tue, 2 Sep 2014 09:42:36 +0000 (11:42 +0200)
committerPiotr Bartosiewicz <p.bartosiewi@partner.samsung.com>
Tue, 2 Sep 2014 09:45:58 +0000 (11:45 +0200)
[Bug/Feature]   Unnecessary complicated log call.
[Cause]         N/A
[Solution]      N/A
[Verification]  Build, install, run.

Change-Id: Ib734727b4384f15c18c68b612437b26da9cfa945

src/logger/logger.cpp
src/logger/logger.hpp

index 1d494d9..ec0855b 100644 (file)
@@ -40,23 +40,16 @@ std::mutex gLogMutex;
 
 } // namespace
 
-Logger::Logger(LogLevel logLevel,
-               const std::string& file,
-               const unsigned int line,
-               const std::string& func,
-               const std::string& rootDir)
-    : mLogLevel(logLevel),
-      mFile(LogFormatter::stripProjectDir(file, rootDir)),
-      mLine(line),
-      mFunc(func)
-{
-}
-
-void Logger::logMessage(const std::string& message)
+void Logger::logMessage(LogLevel logLevel,
+                        const std::string& message,
+                        const std::string& file,
+                        const unsigned int line,
+                        const std::string& func,
+                        const std::string& rootDir)
 {
+    std::string sfile = LogFormatter::stripProjectDir(file, rootDir);
     std::unique_lock<std::mutex> lock(gLogMutex);
-
-    gLogBackendPtr->log(mLogLevel, mFile, mLine, mFunc, message);
+    gLogBackendPtr->log(logLevel, sfile, line, func, message);
 }
 
 void Logger::setLogLevel(const LogLevel level)
index 51846b0..8acc4ff 100644 (file)
@@ -40,42 +40,34 @@ class LogBackend;
 
 class Logger {
 public:
-    Logger(LogLevel logLevel,
-           const std::string& file,
-           const unsigned int line,
-           const std::string& func,
-           const std::string& rootDir);
-
-    void logMessage(const std::string& message);
+    static void logMessage(LogLevel logLevel,
+                           const std::string& message,
+                           const std::string& file,
+                           const unsigned int line,
+                           const std::string& func,
+                           const std::string& rootDir);
 
     static void setLogLevel(const LogLevel level);
     static void setLogLevel(const std::string& level);
     static LogLevel getLogLevel(void);
     static void setLogBackend(LogBackend* pBackend);
-
-private:
-    LogLevel mLogLevel;
-    std::string mFile;
-    unsigned int mLine;
-    std::string mFunc;
 };
 
 } // namespace logger
 
-#define LOG(SEVERITY, MESSAGE) \
-    do { \
-        if (logger::Logger::getLogLevel() <= \
-            logger::LogLevel::SEVERITY) { \
-            std::ostringstream messageStream__; \
-            messageStream__ << MESSAGE; \
-            logger::Logger logger(logger::LogLevel::SEVERITY, \
-                                  __FILE__, \
-                                  __LINE__, \
-                                  __func__, \
-                                  PROJECT_SOURCE_DIR); \
-            logger.logMessage(messageStream__.str()); \
-        } \
-    } while(0)
+#define LOG(SEVERITY, MESSAGE)                                             \
+    do {                                                                   \
+        if (logger::Logger::getLogLevel() <= logger::LogLevel::SEVERITY) { \
+            std::ostringstream messageStream__;                            \
+            messageStream__ << MESSAGE;                                    \
+            logger::Logger::logMessage(logger::LogLevel::SEVERITY,         \
+                                       messageStream__.str(),              \
+                                       __FILE__,                           \
+                                       __LINE__,                           \
+                                       __func__,                           \
+                                       PROJECT_SOURCE_DIR);                \
+        }                                                                  \
+    } while (0)
 
 #define LOGE(MESSAGE) LOG(ERROR, MESSAGE)
 #define LOGW(MESSAGE) LOG(WARN, MESSAGE)