diff --git a/lib/base/logger.cpp b/lib/base/logger.cpp index 2fbab7eecb1..e25595e3725 100644 --- a/lib/base/logger.cpp +++ b/lib/base/logger.cpp @@ -3,7 +3,9 @@ #include "base/logger.hpp" #include "base/logger-ti.cpp" #include "base/application.hpp" +#include "base/dependencygraph.hpp" #include "base/streamlogger.hpp" +#include "base/configobject.hpp" #include "base/configtype.hpp" #include "base/utility.hpp" #include "base/objectlock.hpp" @@ -14,7 +16,10 @@ #endif /* _WIN32 */ #include #include +#include +#include #include +#include using namespace icinga; @@ -354,11 +359,57 @@ Log::~Log() for (const Logger::Ptr& logger : Logger::GetLoggers()) { ObjectLock llock(logger); - if (!logger->IsActive()) + if (!logger->IsActive()) { continue; + } + + if (entry.Severity < logger->GetMinSeverity()) { + continue; + } + + auto filter (logger->GetObjectFilter()); + + if (filter) { + if (!m_Involved) { + continue; + } + + std::set allowed; + auto indirect (DependencyGraph::GetAllParents({m_Involved})); + std::vector intersection; + + indirect.emplace(m_Involved); + + { + 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 (auto& name : objects) { + auto object (ctype->GetObject(name)); + + if (object) { + allowed.emplace(std::move(object)); + } + } + } + } + } + + std::set_intersection(allowed.begin(), allowed.end(), indirect.begin(), indirect.end(), std::back_inserter(intersection)); + + if (intersection.empty()) { + continue; + } + } - if (entry.Severity >= logger->GetMinSeverity()) - logger->ProcessLogEntry(entry); + logger->ProcessLogEntry(entry); #ifdef I2_DEBUG /* I2_DEBUG */ /* Always flush, don't depend on the timer. Enable this for development sprints on Linux/macOS only. Windows crashes. */