Skip to content

Commit

Permalink
Log#~Log(): skip messages based on Logger#object_filter and Dependenc…
Browse files Browse the repository at this point in the history
…yGraph

If Logger#object_filter is set, but doesn't intersect with
Log#m_Involved + DependencyGraph::GetAllParents(), drop the message.
  • Loading branch information
Al2Klimov committed Aug 11, 2023
1 parent 226ea32 commit 33b1596
Showing 1 changed file with 54 additions and 3 deletions.
57 changes: 54 additions & 3 deletions lib/base/logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -14,7 +16,10 @@
#endif /* _WIN32 */
#include <algorithm>
#include <iostream>
#include <iterator>
#include <set>
#include <utility>
#include <vector>

using namespace icinga;

Expand Down Expand Up @@ -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<Object::Ptr> allowed;
auto indirect (DependencyGraph::GetAllParents({m_Involved}));
std::vector<ConfigObject::Ptr> intersection;

indirect.emplace(m_Involved);

{
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 (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. */
Expand Down

0 comments on commit 33b1596

Please sign in to comment.