From 7462c8320a678cc6ab55113a620de9eb93ba418c Mon Sep 17 00:00:00 2001 From: Michael Friedrich Date: Thu, 22 May 2014 12:12:15 +0200 Subject: [PATCH] Add 'notice' severity to *Logger. Refs #6070 --- doc/5-configuring-icinga-2.md | 6 +++--- lib/base/logger.cpp | 5 +++++ lib/base/logger_fwd.h | 1 + lib/base/streamlogger.cpp | 6 ++++++ lib/base/sysloglogger.cpp | 3 +++ lib/remote/apiclient.cpp | 4 ++-- 6 files changed, 20 insertions(+), 5 deletions(-) diff --git a/doc/5-configuring-icinga-2.md b/doc/5-configuring-icinga-2.md index 615fbef42..650dc8bbc 100644 --- a/doc/5-configuring-icinga-2.md +++ b/doc/5-configuring-icinga-2.md @@ -233,7 +233,7 @@ string(value) | Converts the value to a string. number(value) | Converts the value to a number. bool(value) | Converts the value to a bool. log(value) | Writes a message to the log. Non-string values are converted to a JSON string. -log(severity, facility, value) | Writes a message to the log. `severity` can be one of `LogDebug`, `LogInformation`, `LogWarning` and `LogCritical`. Non-string values are converted to a JSON string. +log(severity, facility, value) | Writes a message to the log. `severity` can be one of `LogDebug`, `LogNotice`, `LogInformation`, `LogWarning` and `LogCritical`. Non-string values are converted to a JSON string. exit(integer) | Terminates the application. ### Dictionary Operators @@ -1494,7 +1494,7 @@ Attributes: Name |Description ----------------|---------------- path |**Required.** The log path. - severity |**Optional.** The minimum severity for this log. Can be "debug", "information", "warning" or "critical". Defaults to "information". + severity |**Optional.** The minimum severity for this log. Can be "debug", "notice", "information", "warning" or "critical". Defaults to "information". ### SyslogLogger @@ -1511,7 +1511,7 @@ Attributes: Name |Description ----------------|---------------- - severity |**Optional.** The minimum severity for this log. Can be "debug", "information", "warning" or "critical". Defaults to "warning". + severity |**Optional.** The minimum severity for this log. Can be "debug", "notice", "information", "notice", "warning" or "critical". Defaults to "warning". diff --git a/lib/base/logger.cpp b/lib/base/logger.cpp index d0f5e59f1..86ec150d0 100644 --- a/lib/base/logger.cpp +++ b/lib/base/logger.cpp @@ -40,6 +40,7 @@ bool Logger::m_ConsoleLogEnabled = true; void Logger::StaticInitialize(void) { ScriptVariable::Set("LogDebug", LogDebug, true, true); + ScriptVariable::Set("LogNotice", LogNotice, true, true); ScriptVariable::Set("LogInformation", LogInformation, true, true); ScriptVariable::Set("LogWarning", LogWarning, true, true); ScriptVariable::Set("LogCritical", LogCritical, true, true); @@ -142,6 +143,8 @@ String Logger::SeverityToString(LogSeverity severity) switch (severity) { case LogDebug: return "debug"; + case LogNotice: + return "notice"; case LogInformation: return "information"; case LogWarning: @@ -162,6 +165,8 @@ LogSeverity Logger::StringToSeverity(const String& severity) { if (severity == "debug") return LogDebug; + else if (severity == "notice") + return LogNotice; else if (severity == "information") return LogInformation; else if (severity == "warning") diff --git a/lib/base/logger_fwd.h b/lib/base/logger_fwd.h index 8379c2d14..25d22fc2c 100644 --- a/lib/base/logger_fwd.h +++ b/lib/base/logger_fwd.h @@ -34,6 +34,7 @@ namespace icinga enum LogSeverity { LogDebug, + LogNotice, LogInformation, LogWarning, LogCritical diff --git a/lib/base/streamlogger.cpp b/lib/base/streamlogger.cpp index 8428fe07d..822e94a36 100644 --- a/lib/base/streamlogger.cpp +++ b/lib/base/streamlogger.cpp @@ -97,6 +97,12 @@ void StreamLogger::ProcessLogEntry(std::ostream& stream, bool tty, const LogEntr if (tty) { switch (entry.Severity) { + case LogNotice: + stream << "\x1b[1;34m"; // blue + break; + case LogInformation: + stream << "\x1b[1;32m"; // green + break; case LogWarning: stream << "\x1b[1;33m"; // yellow; break; diff --git a/lib/base/sysloglogger.cpp b/lib/base/sysloglogger.cpp index 0161dec2d..4cd4433ce 100644 --- a/lib/base/sysloglogger.cpp +++ b/lib/base/sysloglogger.cpp @@ -53,6 +53,9 @@ void SyslogLogger::ProcessLogEntry(const LogEntry& entry) case LogDebug: severity = LOG_DEBUG; break; + case LogNotice: + severity = LOG_NOTICE; + break; case LogWarning: severity = LOG_WARNING; break; diff --git a/lib/remote/apiclient.cpp b/lib/remote/apiclient.cpp index e86766839..0799515af 100644 --- a/lib/remote/apiclient.cpp +++ b/lib/remote/apiclient.cpp @@ -191,7 +191,7 @@ void ApiClient::KeepAliveTimerHandler(void) BOOST_FOREACH(const ApiClient::Ptr& client, endpoint->GetClients()) { if (client->m_Seen < timeout) { - Log(LogInformation, "remote", "Closing connection with inactive endpoint '" + endpoint->GetName() + "'"); + Log(LogNotice, "remote", "Closing connection with inactive endpoint '" + endpoint->GetName() + "'"); client->Disconnect(); } } @@ -205,7 +205,7 @@ void ApiClient::KeepAliveTimerHandler(void) BOOST_FOREACH(const ApiClient::Ptr& client, listener->GetAnonymousClients()) { if (client->m_Seen < timeout) { - Log(LogInformation, "remote", "Closing connection with inactive anonymous endpoint '" + client->GetIdentity() + "'"); + Log(LogNotice, "remote", "Closing connection with inactive anonymous endpoint '" + client->GetIdentity() + "'"); client->Disconnect(); } } -- 2.40.0