mirror of
https://github.com/Icinga/icinga2.git
synced 2025-09-23 01:38:11 +02:00
Logger#{OnAllConfigLoaded,SetObjectFilter}(): warn on missing objects for
This commit is contained in:
parent
aaa06575af
commit
0738d6b78f
@ -62,6 +62,19 @@ void Logger::Start(bool runtimeCreated)
|
||||
UpdateMinLogSeverity();
|
||||
}
|
||||
|
||||
void Logger::SetObjectFilter(const Dictionary::Ptr& value, bool suppress_events, const Value& cookie)
|
||||
{
|
||||
ObjectImpl<Logger>::SetObjectFilter(value, suppress_events, cookie);
|
||||
CheckObjectFilter();
|
||||
}
|
||||
|
||||
void Logger::OnAllConfigLoaded()
|
||||
{
|
||||
ObjectImpl<Logger>::OnAllConfigLoaded();
|
||||
m_CalledOnAllConfigLoaded.store(true);
|
||||
CheckObjectFilter();
|
||||
}
|
||||
|
||||
void Logger::Stop(bool runtimeRemoved)
|
||||
{
|
||||
{
|
||||
@ -284,6 +297,38 @@ void Logger::UpdateMinLogSeverity()
|
||||
m_MinLogSeverity.store(result);
|
||||
}
|
||||
|
||||
void Logger::CheckObjectFilter()
|
||||
{
|
||||
if (!m_CalledOnAllConfigLoaded.load()) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto filter (GetObjectFilter());
|
||||
|
||||
if (!filter) {
|
||||
return;
|
||||
}
|
||||
|
||||
ObjectLock lock (filter);
|
||||
|
||||
for (auto& kv : filter) {
|
||||
auto type (Type::GetByName(kv.first));
|
||||
auto ctype (dynamic_cast<ConfigType*>(type.get()));
|
||||
Array::Ptr objects = kv.second;
|
||||
|
||||
if (ctype && objects) {
|
||||
ObjectLock lock (objects);
|
||||
|
||||
for (String object : objects) {
|
||||
if (!ctype->GetObject(object)) {
|
||||
Log(LogWarning, GetReflectionType()->GetName())
|
||||
<< "Missing " << kv.first << " '" << object << "' in object filter of '" << GetName() << "'.";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Log::Log(LogSeverity severity, String facility, const String& message)
|
||||
: Log(severity, std::move(facility))
|
||||
{
|
||||
|
@ -88,6 +88,8 @@ public:
|
||||
|
||||
void SetSeverity(const String& value, bool suppress_events = false, const Value& cookie = Empty) override;
|
||||
void ValidateSeverity(const Lazy<String>& lvalue, const ValidationUtils& utils) final;
|
||||
void SetObjectFilter(const Dictionary::Ptr& value, bool suppress_events = false, const Value& cookie = Empty) override;
|
||||
void OnAllConfigLoaded() override;
|
||||
|
||||
protected:
|
||||
void Start(bool runtimeCreated) override;
|
||||
@ -97,6 +99,8 @@ protected:
|
||||
private:
|
||||
static void UpdateMinLogSeverity();
|
||||
|
||||
void CheckObjectFilter();
|
||||
|
||||
static std::mutex m_Mutex;
|
||||
static std::set<Logger::Ptr> m_Loggers;
|
||||
static bool m_ConsoleLogEnabled;
|
||||
@ -105,6 +109,8 @@ private:
|
||||
static LogSeverity m_ConsoleLogSeverity;
|
||||
static std::mutex m_UpdateMinLogSeverityMutex;
|
||||
static Atomic<LogSeverity> m_MinLogSeverity;
|
||||
|
||||
Atomic<bool> m_CalledOnAllConfigLoaded {false};
|
||||
};
|
||||
|
||||
class Log
|
||||
|
@ -12,7 +12,7 @@ abstract class Logger : ConfigObject
|
||||
[config, set_virtual] String severity {
|
||||
default {{{ return "information"; }}}
|
||||
};
|
||||
[config] Dictionary::Ptr object_filter;
|
||||
[config, set_virtual] Dictionary::Ptr object_filter;
|
||||
};
|
||||
|
||||
validator Logger {
|
||||
|
Loading…
x
Reference in New Issue
Block a user