Skip to content

Commit

Permalink
Logger#{OnAllConfigLoaded,SetObjectFilter}(): warn on missing objects…
Browse files Browse the repository at this point in the history
… for
  • Loading branch information
Al2Klimov committed Aug 15, 2023
1 parent 7dc365a commit d00fc03
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 1 deletion.
45 changes: 45 additions & 0 deletions lib/base/logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
{
Expand Down Expand Up @@ -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))
{
Expand Down
6 changes: 6 additions & 0 deletions lib/base/logger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ class Logger : public ObjectImpl<Logger>

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;
Expand All @@ -97,6 +99,8 @@ class Logger : public ObjectImpl<Logger>
private:
static void UpdateMinLogSeverity();

void CheckObjectFilter();

static std::mutex m_Mutex;
static std::set<Logger::Ptr> m_Loggers;
static bool m_ConsoleLogEnabled;
Expand All @@ -105,6 +109,8 @@ class Logger : public ObjectImpl<Logger>
static LogSeverity m_ConsoleLogSeverity;
static std::mutex m_UpdateMinLogSeverityMutex;
static Atomic<LogSeverity> m_MinLogSeverity;

Atomic<bool> m_CalledOnAllConfigLoaded {false};
};

class Log
Expand Down
2 changes: 1 addition & 1 deletion lib/base/logger.ti
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit d00fc03

Please sign in to comment.