This commit is contained in:
Sajjad Reyhani 2026-05-23 14:32:29 +08:00 committed by GitHub
commit 321460ea83
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 22 additions and 8 deletions

View file

@ -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();
}

View file

@ -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