Skip to content

Commit

Permalink
Disable any debug logs by defaults (#231)
Browse files Browse the repository at this point in the history
  • Loading branch information
awegrzyn authored Mar 4, 2021
1 parent 1243e22 commit 30bfe6d
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/Backends/ApMonBackend.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ ApMonBackend::ApMonBackend(const std::string& path)
{
try {
mApMon = std::make_unique<ApMon>(const_cast<char*>(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()));
}
Expand Down
2 changes: 1 addition & 1 deletion src/Backends/InfluxDB.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ overloaded(Ts...)->overloaded<Ts...>;
InfluxDB::InfluxDB(std::unique_ptr<transports::TransportInterface> 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<std::chrono::system_clock>& timestamp)
Expand Down
2 changes: 1 addition & 1 deletion src/Backends/StdOut.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ inline unsigned long StdOut::convertTimestamp(const std::chrono::time_point<std:
StdOut::StdOut(const std::string& prefix) : mPrefix(prefix)
{
setVerbosisty(Verbosity::Debug);
MonLogger::Get() << "StdOut backend initialized" << MonLogger::End();
MonLogger::Get(Severity::Info) << "StdOut backend initialized" << MonLogger::End();
}

void StdOut::addGlobalTag(std::string_view name, std::string_view value)
Expand Down
24 changes: 17 additions & 7 deletions src/MonLogger.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ namespace monitoring
/// List of possible log severities
enum class Severity { Error = 31,
Warn = 33,
Info = 49 };
Info = 49,
Debug = 50};

/// Simple Monitoring logging class
class MonLogger
Expand All @@ -41,19 +42,21 @@ class MonLogger
template <typename T>
MonLogger& operator<<(const T& log)
{
mStream << log;
if (MonLogger::globalSeverity >= severity) {
mStream << log;
}
return *this;
}

/// Singleton
/// 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;
}

Expand All @@ -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;

Expand All @@ -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<int>(severity) << "m";
severity = desiredSeverity;
*this << "\033[0;" << static_cast<int>(severity) << "m";
}

/// Delete copy and move constructors
Expand Down
2 changes: 1 addition & 1 deletion src/Monitoring.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion src/ProcessMonitor.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ std::vector<Metric> ProcessMonitor::getCpuAndContexts()
auto timeNow = std::chrono::high_resolution_clock::now();
double timePassed = std::chrono::duration_cast<std::chrono::microseconds>(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;
}
Expand Down

0 comments on commit 30bfe6d

Please sign in to comment.