} // 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)
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)