diff options
author | Antony Woods <acron1@gmail.com> | 2014-05-20 23:30:51 +0100 |
---|---|---|
committer | Antony Woods <acron1@gmail.com> | 2014-05-20 23:30:51 +0100 |
commit | 1ae0387a255c7ec891179e3880579368b6cc588d (patch) | |
tree | 806b8b20e50b1ac3fa3204e3be30b5f87c8fd7cf /logging.h | |
parent | dccb246cf8ba7b5480320088a817c29a4a7c8da3 (diff) | |
download | crow-1ae0387a255c7ec891179e3880579368b6cc588d.tar.gz crow-1ae0387a255c7ec891179e3880579368b6cc588d.zip |
Added log level support
Diffstat (limited to 'logging.h')
-rw-r--r-- | logging.h | 20 |
1 files changed, 17 insertions, 3 deletions
@@ -31,12 +31,16 @@ class logger { }; // + static Level currentLevel; + logger(string prefix, logger::Level level) : m_prefix(prefix), m_level(level) { } ~logger() { #ifdef CROW_ENABLE_LOGGING - cerr << "(" << timeStamp() << ") [" << m_prefix << "] " << m_stringStream.str() << endl; + if(m_level <= currentLevel) { + cerr << "(" << timeStamp() << ") [" << m_prefix << "] " << m_stringStream.str() << endl; + } #endif } @@ -45,12 +49,19 @@ class logger { logger& operator<<(T const &value) { #ifdef CROW_ENABLE_LOGGING - m_stringStream << value; + if(m_level <= currentLevel) { + m_stringStream << value; + } #endif return *this; } - private: + // + static void setLogLevel(logger::Level level) { + currentLevel = level; + } + + private: // ostringstream m_stringStream; @@ -58,6 +69,9 @@ class logger { Level m_level; }; +// +logger::Level logger::currentLevel = (Level)CROW_LOG_LEVEL; + #define CROW_LOG_CRITICAL logger("CRITICAL", logger::Level::CRITICAL) #define CROW_LOG_ERROR logger("ERROR ", logger::Level::ERROR) #define CROW_LOG_WARNING logger("WARNING ", logger::Level::WARNING) |