From: Thomas Markwalder Date: Thu, 3 Jul 2025 15:31:58 +0000 (-0400) Subject: [#3992] Fix syslog:facility parsing X-Git-Tag: Kea-2.6.4~3 X-Git-Url: http://git.ipfire.org/gitweb/gitweb.cgi?a=commitdiff_plain;h=eaa4428214f8d56fabc5e8494d5d1e2b72050d80;p=thirdparty%2Fkea.git [#3992] Fix syslog:facility parsing Backports #3921 to v2_6. modified: ChangeLog modified: src/lib/process/log_parser.cc modified: src/lib/process/tests/log_parser_unittests.cc --- diff --git a/ChangeLog b/ChangeLog index 9ecca73e9a..73f4938b7b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2269. [bug] tmark + Corrected an issue in logging configuration when + parsing "syslog:". + (Gitlab #3992, #3921) + 2268. [bug] razvan Fix error handling when detecting a global reservation for the client and global reservatons are explicitly disabled in the diff --git a/src/lib/process/log_parser.cc b/src/lib/process/log_parser.cc index f052730cfc..a438420328 100644 --- a/src/lib/process/log_parser.cc +++ b/src/lib/process/log_parser.cc @@ -174,7 +174,8 @@ void LogConfigParser::parseOutputOptions(std::vector& destin auto output_str = output->stringValue(); if ((output_str == "stdout") || (output_str == "stderr") || - (output_str == "syslog")) { + (output_str == "syslog") || + (output_str.find("syslog:") == 0)) { dest.output_ = output_str; } else { try { diff --git a/src/lib/process/tests/log_parser_unittests.cc b/src/lib/process/tests/log_parser_unittests.cc index b833ed9642..87eef1a599 100644 --- a/src/lib/process/tests/log_parser_unittests.cc +++ b/src/lib/process/tests/log_parser_unittests.cc @@ -632,6 +632,82 @@ TEST_F(LoggingTest, maxsize) { testMaxSize(1000000LL * std::numeric_limits::max(), 1000000LL * std::numeric_limits::max()); } +// Verifies syslog destination +TEST_F(LoggingTest, syslogDestination) { + // Note the backslash must be doubled in the pattern definition. + const char* config_txt = + "{ \"loggers\": [" + " {" + " \"name\": \"kea\"," + " \"output-options\": [" + " {" + " \"output\": \"syslog\"" + " }" + " ]," + " \"severity\": \"INFO\"" + " }" + "]}"; + + ConfigPtr storage(new ConfigBase()); + + LogConfigParser parser(storage); + + // We need to parse properly formed JSON and then extract + // "loggers" element from it. For some reason fromJSON is + // throwing at opening square bracket + ConstElementPtr config = Element::fromJSON(config_txt); + config = config->get("loggers"); + + EXPECT_NO_THROW(parser.parseConfiguration(config)); + + ASSERT_EQ(1, storage->getLoggingInfo().size()); + + EXPECT_EQ("kea", storage->getLoggingInfo()[0].name_); + EXPECT_EQ(isc::log::INFO, storage->getLoggingInfo()[0].severity_); + + ASSERT_EQ(1, storage->getLoggingInfo()[0].destinations_.size()); + // The destination output should NOT include the validated path. + EXPECT_EQ("syslog" , storage->getLoggingInfo()[0].destinations_[0].output_); +} + +// Verifies syslog destination +TEST_F(LoggingTest, syslogPlusFacility) { + // Note the backslash must be doubled in the pattern definition. + const char* config_txt = + "{ \"loggers\": [" + " {" + " \"name\": \"kea\"," + " \"output-options\": [" + " {" + " \"output\": \"syslog:daemon\"" + " }" + " ]," + " \"severity\": \"INFO\"" + " }" + "]}"; + + ConfigPtr storage(new ConfigBase()); + + LogConfigParser parser(storage); + + // We need to parse properly formed JSON and then extract + // "loggers" element from it. For some reason fromJSON is + // throwing at opening square bracket + ConstElementPtr config = Element::fromJSON(config_txt); + config = config->get("loggers"); + + EXPECT_NO_THROW(parser.parseConfiguration(config)); + + ASSERT_EQ(1, storage->getLoggingInfo().size()); + + EXPECT_EQ("kea", storage->getLoggingInfo()[0].name_); + EXPECT_EQ(isc::log::INFO, storage->getLoggingInfo()[0].severity_); + + ASSERT_EQ(1, storage->getLoggingInfo()[0].destinations_.size()); + // The destination output should NOT include the validated path. + EXPECT_EQ("syslog:daemon" , storage->getLoggingInfo()[0].destinations_[0].output_); +} + /// @todo Add tests for malformed logging configuration /// @todo There is no easy way to test applyConfiguration() and defaultLogging().