From 4741c5341dee4874c105c08f0ca9ded74f80b15a Mon Sep 17 00:00:00 2001 From: Peter Nguyen Date: Mon, 16 Sep 2024 23:42:11 -0700 Subject: [PATCH] Add filter channel to LocalServer.cpp and BaseDaemon.cpp --- programs/local/LocalServer.cpp | 7 ++++++- src/Daemon/BaseDaemon.cpp | 8 +++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/programs/local/LocalServer.cpp b/programs/local/LocalServer.cpp index 184f147a86a..ad665b5df35 100644 --- a/programs/local/LocalServer.cpp +++ b/programs/local/LocalServer.cpp @@ -34,6 +34,7 @@ #include #include #include +#include #include #include #include @@ -611,10 +612,14 @@ void LocalServer::processConfig() if (getClientConfiguration().has("server_logs_file")) { + std::string pos_pattern = getClientConfiguration().getRawString("logger.message_regexp", ""); + std::string neg_pattern = getClientConfiguration().getRawString("logger.message_regexp_negative", ""); + Poco::AutoPtr filter_channel = new OwnFilteringChannel(new Poco::SimpleFileChannel(server_logs_file), nullptr, pos_pattern, neg_pattern); + auto poco_logs_level = Poco::Logger::parseLevel(level); Poco::Logger::root().setLevel(poco_logs_level); Poco::AutoPtr pf = new OwnPatternFormatter; - Poco::AutoPtr log = new OwnFormattingChannel(pf, new Poco::SimpleFileChannel(server_logs_file)); + Poco::AutoPtr log = new OwnFormattingChannel(pf, filter_channel); Poco::Logger::root().setChannel(log); } else diff --git a/src/Daemon/BaseDaemon.cpp b/src/Daemon/BaseDaemon.cpp index d4d3ad58ddd..be53198119e 100644 --- a/src/Daemon/BaseDaemon.cpp +++ b/src/Daemon/BaseDaemon.cpp @@ -1,3 +1,4 @@ +#include "Loggers/OwnFilteringChannel.h" #pragma clang diagnostic ignored "-Wreserved-identifier" #include @@ -625,7 +626,12 @@ void BaseDaemon::setupWatchdog() pf = new OwnJSONPatternFormatter(config()); else pf = new OwnPatternFormatter; - Poco::AutoPtr log = new OwnFormattingChannel(pf, new Poco::ConsoleChannel(std::cerr)); + + // Apply regexp filtering after receiving the formatting channel + std::string pos_pattern = config().getRawString("logger.message_regexp", ""); + std::string neg_pattern = config().getRawString("logger.message_regexp_negative", ""); + Poco::AutoPtr filter_channel = new OwnFilteringChannel(new Poco::ConsoleChannel(std::cerr), nullptr, pos_pattern, neg_pattern); + Poco::AutoPtr log = new OwnFormattingChannel(pf, filter_channel); logger().setChannel(log); }