mirror of
https://github.com/Icinga/icinga2.git
synced 2025-09-23 17:57:54 +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();
|
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)
|
void Logger::Stop(bool runtimeRemoved)
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
@ -284,6 +297,38 @@ void Logger::UpdateMinLogSeverity()
|
|||||||
m_MinLogSeverity.store(result);
|
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::Log(LogSeverity severity, String facility, const String& message)
|
||||||
: Log(severity, std::move(facility))
|
: 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 SetSeverity(const String& value, bool suppress_events = false, const Value& cookie = Empty) override;
|
||||||
void ValidateSeverity(const Lazy<String>& lvalue, const ValidationUtils& utils) final;
|
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:
|
protected:
|
||||||
void Start(bool runtimeCreated) override;
|
void Start(bool runtimeCreated) override;
|
||||||
@ -97,6 +99,8 @@ protected:
|
|||||||
private:
|
private:
|
||||||
static void UpdateMinLogSeverity();
|
static void UpdateMinLogSeverity();
|
||||||
|
|
||||||
|
void CheckObjectFilter();
|
||||||
|
|
||||||
static std::mutex m_Mutex;
|
static std::mutex m_Mutex;
|
||||||
static std::set<Logger::Ptr> m_Loggers;
|
static std::set<Logger::Ptr> m_Loggers;
|
||||||
static bool m_ConsoleLogEnabled;
|
static bool m_ConsoleLogEnabled;
|
||||||
@ -105,6 +109,8 @@ private:
|
|||||||
static LogSeverity m_ConsoleLogSeverity;
|
static LogSeverity m_ConsoleLogSeverity;
|
||||||
static std::mutex m_UpdateMinLogSeverityMutex;
|
static std::mutex m_UpdateMinLogSeverityMutex;
|
||||||
static Atomic<LogSeverity> m_MinLogSeverity;
|
static Atomic<LogSeverity> m_MinLogSeverity;
|
||||||
|
|
||||||
|
Atomic<bool> m_CalledOnAllConfigLoaded {false};
|
||||||
};
|
};
|
||||||
|
|
||||||
class Log
|
class Log
|
||||||
|
@ -12,7 +12,7 @@ abstract class Logger : ConfigObject
|
|||||||
[config, set_virtual] String severity {
|
[config, set_virtual] String severity {
|
||||||
default {{{ return "information"; }}}
|
default {{{ return "information"; }}}
|
||||||
};
|
};
|
||||||
[config] Dictionary::Ptr object_filter;
|
[config, set_virtual] Dictionary::Ptr object_filter;
|
||||||
};
|
};
|
||||||
|
|
||||||
validator Logger {
|
validator Logger {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user