From 9642447fb0c7d10e06452d0d153a1a00d7f60a65 Mon Sep 17 00:00:00 2001 From: "Matthias P. Braendli" Date: Fri, 15 Apr 2016 10:01:01 +0200 Subject: Add discard level to Log --- src/Log.cpp | 8 ++++++++ src/Log.h | 12 ++++++++---- 2 files changed, 16 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/Log.cpp b/src/Log.cpp index 75380dd..35f3fae 100644 --- a/src/Log.cpp +++ b/src/Log.cpp @@ -38,6 +38,10 @@ void Logger::register_backend(LogBackend* backend) { void Logger::log(log_level_t level, const char* fmt, ...) { + if (level == discard) { + return; + } + int size = 100; std::string str; va_list ap; @@ -61,6 +65,10 @@ void Logger::log(log_level_t level, const char* fmt, ...) void Logger::logstr(log_level_t level, std::string message) { + if (level == discard) { + return; + } + /* Remove a potential trailing newline. * It doesn't look good in syslog */ diff --git a/src/Log.h b/src/Log.h index 2873818..e14ca37 100644 --- a/src/Log.h +++ b/src/Log.h @@ -44,10 +44,10 @@ #define SYSLOG_IDENT "ODR-DabMux" #define SYSLOG_FACILITY LOG_LOCAL0 -enum log_level_t {debug = 0, info, warn, error, alert, emerg}; +enum log_level_t {debug = 0, info, warn, error, alert, emerg, discard}; static const std::string levels_as_str[] = - { " ", " ", "WARN ", "ERROR", "ALERT", "EMERG"} ; + { " ", " ", "WARN ", "ERROR", "ALERT", "EMERG", "-----"} ; /** Abstract class all backends must inherit from */ class LogBackend { @@ -166,13 +166,17 @@ class LogLine { // Push the new element into the stringstream template LogLine& operator<<(T s) { - os << s; + if (level_ != discard) { + os << s; + } return *this; } ~LogLine() { - logger_->logstr(level_, os.str()); + if (level_ != discard) { + logger_->logstr(level_, os.str()); + } } private: -- cgit v1.2.3