diff --git a/src/utils/log.cpp b/src/utils/log.cpp index c48a15f1..63680a62 100644 --- a/src/utils/log.cpp +++ b/src/utils/log.cpp @@ -44,7 +44,7 @@ bool Logger::reopen(const std::string& fn) if (!m_tocerr && m_stream.is_open()) { m_stream.close(); } - if (!m_fn.empty() && m_fn.compare("stderr")) { + if (!m_fn.empty() && m_fn != "stderr") { m_stream.open(m_fn, std::fstream::out | std::ofstream::trunc); if (!m_stream.is_open()) { cerr << "Logger::Logger: log open failed: for [" << diff --git a/src/utils/log.h b/src/utils/log.h index d4d885ef..3d839506 100644 --- a/src/utils/log.h +++ b/src/utils/log.h @@ -48,7 +48,7 @@ public: * output. Creates the singleton logger object. Only the first * call changes the state, further ones just return the Logger * pointer. */ - static Logger *getTheLog(const std::string& fn); + static Logger *getTheLog(const std::string& fn = std::string()); /** Close and reopen the output file. For rotating the log: rename * then reopen. */ @@ -80,6 +80,14 @@ public: int getloglevel() const { return m_loglevel; } + /** @brief Retrieve current log file name */ + const std::string& getlogfilename() const { + return m_fn; + } + /** @brief Logging to stderr ? */ + bool logisstderr() const { + return m_tocerr; + } /** @brief turn date logging on or off (default is off) */ void logthedate(bool onoff) { @@ -121,11 +129,11 @@ private: Logger& operator=(const Logger &); }; -#define LOGGER_PRT (Logger::getTheLog("")->getstream()) +#define LOGGER_PRT (Logger::getTheLog()->getstream()) #if LOGGER_THREADSAFE #define LOGGER_LOCK \ - std::unique_lock lock(Logger::getTheLog("")->getmutex()) + std::unique_lock lock(Logger::getTheLog()->getmutex()) #else #define LOGGER_LOCK #endif @@ -134,11 +142,11 @@ private: #define LOGGER_LOCAL_LOGINC 0 #endif -#define LOGGER_LEVEL (Logger::getTheLog("")->getloglevel() + \ +#define LOGGER_LEVEL (Logger::getTheLog()->getloglevel() + \ LOGGER_LOCAL_LOGINC) -#define LOGGER_DATE (Logger::getTheLog("")->loggingdate() ? \ - Logger::getTheLog("")->datestring() : "") +#define LOGGER_DATE (Logger::getTheLog()->loggingdate() ? \ + Logger::getTheLog()->datestring() : "") #define LOGGER_DOLOG(L,X) LOGGER_PRT << LOGGER_DATE << ":" << L << ":" << \ __FILE__ << ":" << __LINE__ << "::" << X \