Skip to content

Commit

Permalink
Introduce Logger#object_filter
Browse files Browse the repository at this point in the history
  • Loading branch information
Al2Klimov committed Aug 11, 2023
1 parent 0d58029 commit f59082d
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 0 deletions.
41 changes: 41 additions & 0 deletions lib/base/logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,47 @@ void Logger::Stop(bool runtimeRemoved)
ObjectImpl<Logger>::Stop(runtimeRemoved);
}

void Logger::ValidateObjectFilter(const Lazy<Dictionary::Ptr>& lvalue, const ValidationUtils& utils)
{
ObjectImpl<Logger>::ValidateObjectFilter(lvalue, utils);

auto filter (lvalue());

if (filter) {
ObjectLock lock (filter);

for (auto& kv : filter) {
auto type (Type::GetByName(kv.first));

if (!type) {
BOOST_THROW_EXCEPTION(
ValidationError(this, {"object_filter"}, "No such type: '" + kv.first + "'")
);
}

if (!dynamic_cast<ConfigType*>(type.get())) {
BOOST_THROW_EXCEPTION(
ValidationError(this, {"object_filter"}, "Not a config object type: '" + kv.first + "'")
);
}

Array::Ptr objects = kv.second;

if (objects) {
ObjectLock lock (objects);

for (auto& object : objects) {
if (object.GetType() != ValueString) {
BOOST_THROW_EXCEPTION(
ValidationError(this, {"object_filter", kv.first}, "Must be an array of strings.")
);
}
}
}
}
}
}

std::set<Logger::Ptr> Logger::GetLoggers()
{
std::unique_lock<std::mutex> lock(m_Mutex);
Expand Down
1 change: 1 addition & 0 deletions lib/base/logger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ class Logger : public ObjectImpl<Logger>
protected:
void Start(bool runtimeCreated) override;
void Stop(bool runtimeRemoved) override;
void ValidateObjectFilter(const Lazy<Dictionary::Ptr>& lvalue, const ValidationUtils& utils) override;

private:
static void UpdateMinLogSeverity();
Expand Down
7 changes: 7 additions & 0 deletions lib/base/logger.ti
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ abstract class Logger : ConfigObject
[config, virtual] String severity {
default {{{ return "information"; }}}
};
[config] Dictionary::Ptr object_filter;
};

validator Logger {
Dictionary object_filter {
Array "*";
};
};

}

0 comments on commit f59082d

Please sign in to comment.