diff --git a/lib/base/logger.cpp b/lib/base/logger.cpp index b7158fb14e2..042d01a3f05 100644 --- a/lib/base/logger.cpp +++ b/lib/base/logger.cpp @@ -62,6 +62,19 @@ void Logger::Start(bool runtimeCreated) UpdateMinLogSeverity(); } +void Logger::SetObjectFilter(const Dictionary::Ptr& value, bool suppress_events, const Value& cookie) +{ + ObjectImpl::SetObjectFilter(value, suppress_events, cookie); + CheckObjectFilter(); +} + +void Logger::OnAllConfigLoaded() +{ + ObjectImpl::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(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)) { diff --git a/lib/base/logger.hpp b/lib/base/logger.hpp index 1c0215cc74e..cdb4e39c13a 100644 --- a/lib/base/logger.hpp +++ b/lib/base/logger.hpp @@ -88,6 +88,8 @@ class Logger : public ObjectImpl void SetSeverity(const String& value, bool suppress_events = false, const Value& cookie = Empty) override; void ValidateSeverity(const Lazy& 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 @@ class Logger : public ObjectImpl private: static void UpdateMinLogSeverity(); + void CheckObjectFilter(); + static std::mutex m_Mutex; static std::set m_Loggers; static bool m_ConsoleLogEnabled; @@ -105,6 +109,8 @@ class Logger : public ObjectImpl static LogSeverity m_ConsoleLogSeverity; static std::mutex m_UpdateMinLogSeverityMutex; static Atomic m_MinLogSeverity; + + Atomic m_CalledOnAllConfigLoaded {false}; }; class Log diff --git a/lib/base/logger.ti b/lib/base/logger.ti index 88544ea39ee..7a788d3c8c4 100644 --- a/lib/base/logger.ti +++ b/lib/base/logger.ti @@ -12,7 +12,7 @@ abstract class Logger : ConfigObject [config, virtual] String severity { default {{{ return "information"; }}} }; - [config] Dictionary::Ptr object_filter; + [config, set_virtual] Dictionary::Ptr object_filter; }; validator Logger {