mirror of
https://github.com/Icinga/icinga2.git
synced 2026-05-28 04:12:13 -04:00
Merge 3c0d01088e into f63bbec4ab
This commit is contained in:
commit
321460ea83
2 changed files with 22 additions and 8 deletions
|
|
@ -87,19 +87,28 @@ std::set<Logger::Ptr> Logger::GetLoggers()
|
|||
*
|
||||
* @returns The minimum severity.
|
||||
*/
|
||||
LogSeverity Logger::GetMinSeverity() const
|
||||
LogSeverity Logger::GetMinSeverity()
|
||||
{
|
||||
if (min_severity == boost::none) {
|
||||
CacheMinSeverity();
|
||||
}
|
||||
return *min_severity;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves and caches the minimum severity for this logger.
|
||||
*/
|
||||
void Logger::CacheMinSeverity()
|
||||
{
|
||||
String severity = GetSeverity();
|
||||
if (severity.IsEmpty())
|
||||
return LogInformation;
|
||||
min_severity.emplace(LogInformation);
|
||||
else {
|
||||
LogSeverity ls = LogInformation;
|
||||
|
||||
try {
|
||||
ls = Logger::StringToSeverity(severity);
|
||||
} catch (const std::exception&) { /* use the default level */ }
|
||||
|
||||
return ls;
|
||||
} catch (const std::exception &) { /* use the default level */ }
|
||||
min_severity.emplace(ls);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -204,7 +213,7 @@ bool Logger::IsTimestampEnabled()
|
|||
void Logger::SetSeverity(const String& value, bool suppress_events, const Value& cookie)
|
||||
{
|
||||
ObjectImpl<Logger>::SetSeverity(value, suppress_events, cookie);
|
||||
|
||||
min_severity.emplace(StringToSeverity(value));
|
||||
UpdateMinLogSeverity();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@
|
|||
#include <optional>
|
||||
#include <set>
|
||||
#include <sstream>
|
||||
#include <boost/optional.hpp>
|
||||
|
||||
namespace icinga
|
||||
{
|
||||
|
|
@ -56,7 +57,7 @@ public:
|
|||
static String SeverityToString(LogSeverity severity);
|
||||
static LogSeverity StringToSeverity(const String& severity);
|
||||
|
||||
LogSeverity GetMinSeverity() const;
|
||||
LogSeverity GetMinSeverity();
|
||||
|
||||
/**
|
||||
* Processes the log entry and writes it to the log that is
|
||||
|
|
@ -106,6 +107,10 @@ private:
|
|||
static LogSeverity m_ConsoleLogSeverity;
|
||||
static std::mutex m_UpdateMinLogSeverityMutex;
|
||||
static Atomic<LogSeverity> m_MinLogSeverity;
|
||||
|
||||
void CacheMinSeverity();
|
||||
|
||||
boost::optional<LogSeverity> min_severity;
|
||||
};
|
||||
|
||||
class Log
|
||||
|
|
|
|||
Loading…
Reference in a new issue