log: add utility methods and default param
This commit is contained in:
parent
30d27b441f
commit
3e72a11932
@ -44,7 +44,7 @@ bool Logger::reopen(const std::string& fn)
|
|||||||
if (!m_tocerr && m_stream.is_open()) {
|
if (!m_tocerr && m_stream.is_open()) {
|
||||||
m_stream.close();
|
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);
|
m_stream.open(m_fn, std::fstream::out | std::ofstream::trunc);
|
||||||
if (!m_stream.is_open()) {
|
if (!m_stream.is_open()) {
|
||||||
cerr << "Logger::Logger: log open failed: for [" <<
|
cerr << "Logger::Logger: log open failed: for [" <<
|
||||||
|
|||||||
@ -48,7 +48,7 @@ public:
|
|||||||
* output. Creates the singleton logger object. Only the first
|
* output. Creates the singleton logger object. Only the first
|
||||||
* call changes the state, further ones just return the Logger
|
* call changes the state, further ones just return the Logger
|
||||||
* pointer. */
|
* 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
|
/** Close and reopen the output file. For rotating the log: rename
|
||||||
* then reopen. */
|
* then reopen. */
|
||||||
@ -80,6 +80,14 @@ public:
|
|||||||
int getloglevel() const {
|
int getloglevel() const {
|
||||||
return m_loglevel;
|
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) */
|
/** @brief turn date logging on or off (default is off) */
|
||||||
void logthedate(bool onoff) {
|
void logthedate(bool onoff) {
|
||||||
@ -121,11 +129,11 @@ private:
|
|||||||
Logger& operator=(const Logger &);
|
Logger& operator=(const Logger &);
|
||||||
};
|
};
|
||||||
|
|
||||||
#define LOGGER_PRT (Logger::getTheLog("")->getstream())
|
#define LOGGER_PRT (Logger::getTheLog()->getstream())
|
||||||
|
|
||||||
#if LOGGER_THREADSAFE
|
#if LOGGER_THREADSAFE
|
||||||
#define LOGGER_LOCK \
|
#define LOGGER_LOCK \
|
||||||
std::unique_lock<std::recursive_mutex> lock(Logger::getTheLog("")->getmutex())
|
std::unique_lock<std::recursive_mutex> lock(Logger::getTheLog()->getmutex())
|
||||||
#else
|
#else
|
||||||
#define LOGGER_LOCK
|
#define LOGGER_LOCK
|
||||||
#endif
|
#endif
|
||||||
@ -134,11 +142,11 @@ private:
|
|||||||
#define LOGGER_LOCAL_LOGINC 0
|
#define LOGGER_LOCAL_LOGINC 0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define LOGGER_LEVEL (Logger::getTheLog("")->getloglevel() + \
|
#define LOGGER_LEVEL (Logger::getTheLog()->getloglevel() + \
|
||||||
LOGGER_LOCAL_LOGINC)
|
LOGGER_LOCAL_LOGINC)
|
||||||
|
|
||||||
#define LOGGER_DATE (Logger::getTheLog("")->loggingdate() ? \
|
#define LOGGER_DATE (Logger::getTheLog()->loggingdate() ? \
|
||||||
Logger::getTheLog("")->datestring() : "")
|
Logger::getTheLog()->datestring() : "")
|
||||||
|
|
||||||
#define LOGGER_DOLOG(L,X) LOGGER_PRT << LOGGER_DATE << ":" << L << ":" << \
|
#define LOGGER_DOLOG(L,X) LOGGER_PRT << LOGGER_DATE << ":" << L << ":" << \
|
||||||
__FILE__ << ":" << __LINE__ << "::" << X \
|
__FILE__ << ":" << __LINE__ << "::" << X \
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user