From 30bfe6d3c4248fd6d36dfffd205dae18dd391c36 Mon Sep 17 00:00:00 2001 From: Adam Wegrzynek Date: Thu, 4 Mar 2021 16:23:15 +0100 Subject: [PATCH] Disable any debug logs by defaults (#231) --- src/Backends/ApMonBackend.cxx | 2 +- src/Backends/InfluxDB.cxx | 2 +- src/Backends/StdOut.cxx | 2 +- src/MonLogger.h | 24 +++++++++++++++++------- src/Monitoring.cxx | 2 +- src/ProcessMonitor.cxx | 2 +- 6 files changed, 22 insertions(+), 12 deletions(-) diff --git a/src/Backends/ApMonBackend.cxx b/src/Backends/ApMonBackend.cxx index 9e5086f69..3542a4660 100644 --- a/src/Backends/ApMonBackend.cxx +++ b/src/Backends/ApMonBackend.cxx @@ -39,7 +39,7 @@ ApMonBackend::ApMonBackend(const std::string& path) { try { mApMon = std::make_unique(const_cast(path.c_str())); - MonLogger::Get() << "ApMon backend initialized" << MonLogger::End(); + MonLogger::Get(Severity::Info) << "ApMon backend initialized" << MonLogger::End(); } catch (std::runtime_error& e) { throw MonitoringException("ApMonBackend initialization", std::string(e.what())); } diff --git a/src/Backends/InfluxDB.cxx b/src/Backends/InfluxDB.cxx index 624ec38b4..d3b34de27 100644 --- a/src/Backends/InfluxDB.cxx +++ b/src/Backends/InfluxDB.cxx @@ -39,7 +39,7 @@ overloaded(Ts...)->overloaded; InfluxDB::InfluxDB(std::unique_ptr transport) : mTransport(std::move(transport)) { - MonLogger::Get() << "InfluxDB backend initialized" << MonLogger::End(); + MonLogger::Get(Severity::Info) << "InfluxDB backend initialized" << MonLogger::End(); } inline unsigned long InfluxDB::convertTimestamp(const std::chrono::time_point& timestamp) diff --git a/src/Backends/StdOut.cxx b/src/Backends/StdOut.cxx index 4122b265b..8dbdaaa8b 100644 --- a/src/Backends/StdOut.cxx +++ b/src/Backends/StdOut.cxx @@ -43,7 +43,7 @@ inline unsigned long StdOut::convertTimestamp(const std::chrono::time_point MonLogger& operator<<(const T& log) { - mStream << log; + if (MonLogger::globalSeverity >= severity) { + mStream << log; + } return *this; } @@ -49,11 +52,11 @@ class MonLogger /// Returns Logger instance with current date and given severity /// \param severity - severity level /// \return - logger instance - static MonLogger& Get(Severity severity = Severity::Info) + static MonLogger& Get(Severity severity = Severity::Debug) { static MonLogger loggerInstance; + loggerInstance.instanceSeverity(severity); loggerInstance.setDate(); - loggerInstance.setSeverity(severity); return loggerInstance; } @@ -64,7 +67,13 @@ class MonLogger return "\033[0m\n"; } + /// Currently set severity + const Severity globalSeverity = Severity::Info; + private: + /// Instance severity + Severity severity; + /// Log stream std::ostream& mStream; @@ -77,14 +86,15 @@ class MonLogger void setDate() { auto now = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now()); - mStream << std::put_time(std::localtime(&now), "%Y-%m-%d %X") << "\t" << "Monitoring" << "\t"; + *this << std::put_time(std::localtime(&now), "%Y-%m-%d %X") << "\t" << "Monitoring" << "\t"; } /// Sets log color based on severity /// \param severity - log severity - void setSeverity(Severity severity) + void instanceSeverity(Severity desiredSeverity) { - mStream << "\033[0;" << static_cast(severity) << "m"; + severity = desiredSeverity; + *this << "\033[0;" << static_cast(severity) << "m"; } /// Delete copy and move constructors diff --git a/src/Monitoring.cxx b/src/Monitoring.cxx index 3527838a0..c9905f250 100644 --- a/src/Monitoring.cxx +++ b/src/Monitoring.cxx @@ -90,7 +90,7 @@ void Monitoring::enableProcessMonitoring(const unsigned int interval) #ifdef O2_MONITORING_OS_LINUX MonLogger::Get() << "Process Monitor : Automatic updates enabled" << MonLogger::End(); #else - MonLogger::Get() << "!! Process Monitor : Limited metrics available" << MonLogger::End(); + MonLogger::Get() << "Process Monitor : Limited metrics available" << MonLogger::End(); #endif } diff --git a/src/ProcessMonitor.cxx b/src/ProcessMonitor.cxx index 153388733..17cb6e2f9 100644 --- a/src/ProcessMonitor.cxx +++ b/src/ProcessMonitor.cxx @@ -102,7 +102,7 @@ std::vector ProcessMonitor::getCpuAndContexts() auto timeNow = std::chrono::high_resolution_clock::now(); double timePassed = std::chrono::duration_cast(timeNow - mTimeLastRun).count(); if (timePassed < 950) { - MonLogger::Get() << "[WARN] Do not invoke Process Monitor more frequent then every 1s" << MonLogger::End(); + MonLogger::Get(Severity::Warn) << "Do not invoke Process Monitor more frequent then every 1s" << MonLogger::End(); metrics.emplace_back("processPerformance"); return metrics; }