]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#3754] backport #3594 to 2.6.2
authorRazvan Becheriu <razvan@isc.org>
Wed, 19 Feb 2025 18:01:03 +0000 (20:01 +0200)
committerRazvan Becheriu <razvan@isc.org>
Mon, 3 Mar 2025 13:06:18 +0000 (15:06 +0200)
doc/sphinx/arm/logging.rst
src/lib/process/log_parser.cc
src/lib/process/process_messages.cc
src/lib/process/process_messages.h
src/lib/process/process_messages.mes
src/lib/process/tests/log_parser_unittests.cc

index 4add84f989855f73c90124ec89ad755586670dcb..2e91edf49c84a799783cb367dc0a5ea768819c58 100644 (file)
@@ -628,12 +628,15 @@ where log messages are sent and are explained in detail below.
    The alias ``output-options`` was added in Kea 2.5.1, to be used
    interchangeably with the previous ``output_options`` configuration key.
    This was done to keep all configuration keys consistent, i.e.
-   using a hyphen (`-`) instead of an underscore (`_`) in the key name. Currently,
-   both configuration keys are considered correct and mean the same to Kea parsers.
+   using a hyphen (`-`) instead of an underscore (`_`) in the key name.
 
    As of Kea 2.5.2, ``output-options`` becomes the default configuration key
    and ``output_options`` can be used as an alias.
 
+   As of Kea 2.6.2, ``output_options`` configuration key has been deprecated and
+   will be removed in future versions. Please consider updating your
+   configuration by switching to using ``output-options`` instead.
+
 The ``output`` (string) Option
 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 
index 8db8355c727a489d402c2a22a8f98c35c8569b90..c0cc19683d42ae9be8b80f112f10ce50e55526c5 100644 (file)
@@ -6,6 +6,7 @@
 
 #include <config.h>
 #include <cc/data.h>
+#include <process/d_log.h>
 #include <process/log_parser.h>
 #include <boost/lexical_cast.hpp>
 #include <log/logger_specification.h>
@@ -88,9 +89,9 @@ void LogConfigParser::parseConfigEntry(isc::data::ConstElementPtr entry) {
                 isc_throw(BadValue, "");
             }
         } catch (...) {
-            isc_throw(BadValue, "Unsupported debuglevel value '"
-                      << debuglevel_ptr->stringValue()
-                      << "', expected 0-99 ("
+            isc_throw(BadValue, "Unsupported debuglevel value "
+                      << debuglevel_ptr->intValue()
+                      << ", expected 0-99 ("
                       << debuglevel_ptr->getPosition() << ")");
         }
     }
@@ -104,6 +105,19 @@ void LogConfigParser::parseConfigEntry(isc::data::ConstElementPtr entry) {
     }
 
     isc::data::ConstElementPtr output_options = entry->get("output-options");
+    isc::data::ConstElementPtr deprecated_output_options = entry->get("output_options");
+
+    if (output_options && deprecated_output_options) {
+        isc_throw(BadValue, "Only one of 'output-options' and 'output_options' may be specified.");
+    }
+
+    if (deprecated_output_options) {
+        LOG_WARN(dctl_logger, DCTL_DEPRECATED_OUTPUT_OPTIONS);
+        output_options = deprecated_output_options;
+        ElementPtr mutable_element = boost::const_pointer_cast<Element>(entry);
+        mutable_element->remove("output_options");
+        mutable_element->set("output-options", output_options);
+    }
 
     if (output_options) {
         parseOutputOptions(info.destinations_, output_options);
index bd19813f1cf97e620a6962317dfbe572b2c54720..f6e3e9aa4f930b1262567ad52c488819f218275b 100644 (file)
@@ -22,6 +22,7 @@ extern const isc::log::MessageID DCTL_CONFIG_START = "DCTL_CONFIG_START";
 extern const isc::log::MessageID DCTL_CONFIG_STUB = "DCTL_CONFIG_STUB";
 extern const isc::log::MessageID DCTL_CONFIG_UPDATE = "DCTL_CONFIG_UPDATE";
 extern const isc::log::MessageID DCTL_DB_OPEN_CONNECTION_WITH_RETRY_FAILED = "DCTL_DB_OPEN_CONNECTION_WITH_RETRY_FAILED";
+extern const isc::log::MessageID DCTL_DEPRECATED_OUTPUT_OPTIONS = "DCTL_DEPRECATED_OUTPUT_OPTIONS";
 extern const isc::log::MessageID DCTL_DEVELOPMENT_VERSION = "DCTL_DEVELOPMENT_VERSION";
 extern const isc::log::MessageID DCTL_INIT_PROCESS = "DCTL_INIT_PROCESS";
 extern const isc::log::MessageID DCTL_INIT_PROCESS_FAIL = "DCTL_INIT_PROCESS_FAIL";
@@ -60,6 +61,7 @@ const char* values[] = {
     "DCTL_CONFIG_STUB", "%1 configuration stub handler called",
     "DCTL_CONFIG_UPDATE", "%1 updated configuration received: %2",
     "DCTL_DB_OPEN_CONNECTION_WITH_RETRY_FAILED", "Failed to connect to database: %1 with error: %2",
+    "DCTL_DEPRECATED_OUTPUT_OPTIONS", "The output_options parameter is deprecated. Use output-options parameter instead.",
     "DCTL_DEVELOPMENT_VERSION", "This software is a development branch of Kea. It is not recommended for production use.",
     "DCTL_INIT_PROCESS", "%1 initializing the application",
     "DCTL_INIT_PROCESS_FAIL", "%1 application initialization failed: %2",
index 8811e5172b359e954dcc5086c3efaf49d6ae3d51..72fa1a148c452a41fd06dc7c7ba8582240dc3e70 100644 (file)
@@ -23,6 +23,7 @@ extern const isc::log::MessageID DCTL_CONFIG_START;
 extern const isc::log::MessageID DCTL_CONFIG_STUB;
 extern const isc::log::MessageID DCTL_CONFIG_UPDATE;
 extern const isc::log::MessageID DCTL_DB_OPEN_CONNECTION_WITH_RETRY_FAILED;
+extern const isc::log::MessageID DCTL_DEPRECATED_OUTPUT_OPTIONS;
 extern const isc::log::MessageID DCTL_DEVELOPMENT_VERSION;
 extern const isc::log::MessageID DCTL_INIT_PROCESS;
 extern const isc::log::MessageID DCTL_INIT_PROCESS_FAIL;
index d0eb11e6d5553f18cd1fec200084952f65e9ee79..aa20591cee93207ae1c5b8c1adf576c55054d586 100644 (file)
@@ -81,6 +81,10 @@ the configuration database. The operation started a retry to connect procedure.
 The database access string with password redacted is logged, along with the
 error and details for the reconnect procedure.
 
+% DCTL_DEPRECATED_OUTPUT_OPTIONS The output_options parameter is deprecated. Use output-options parameter instead.
+This warning message is displayed when deprecated output_options is used instead
+of output-options.
+
 % DCTL_DEVELOPMENT_VERSION This software is a development branch of Kea. It is not recommended for production use.
 This warning message is displayed when the version is a development
 (vs stable) one: the second number of the version is odd.
index 43c30541d7ae4c5298cf3e7d0ec047da650d07f2..448c471551abebf99625c6a0e0ee75494a4a67dc 100644 (file)
@@ -132,6 +132,99 @@ TEST_F(LoggingTest, parsingConsoleOutput) {
     EXPECT_TRUE(storage->getLoggingInfo()[0].destinations_[0].flush_);
 }
 
+// This test checks that deprecated parameter output_options is accepted.
+TEST_F(LoggingTest, parsingDeprecatedOutputOptions) {
+
+    const char* config_txt =
+    "{ \"loggers\": ["
+    "    {"
+    "        \"name\": \"kea\","
+    "        \"output_options\": ["
+    "            {"
+    "                \"output\": \"stdout\","
+    "                \"flush\": true"
+    "            }"
+    "        ],"
+    "        \"debuglevel\": 99,"
+    "        \"severity\": \"DEBUG\""
+    "    }"
+    "]}";
+
+    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");
+
+    ASSERT_EQ(1, config->size());
+    ASSERT_TRUE(config->get(0)->get("output_options"));
+    ASSERT_FALSE(config->get(0)->get("output-options"));
+
+    EXPECT_NO_THROW(parser.parseConfiguration(config));
+
+    ASSERT_EQ(1, storage->getLoggingInfo().size());
+
+    EXPECT_EQ("kea", storage->getLoggingInfo()[0].name_);
+    EXPECT_EQ(99, storage->getLoggingInfo()[0].debuglevel_);
+    EXPECT_EQ(isc::log::DEBUG, storage->getLoggingInfo()[0].severity_);
+
+    ASSERT_EQ(1, storage->getLoggingInfo()[0].destinations_.size());
+    EXPECT_EQ("stdout" , storage->getLoggingInfo()[0].destinations_[0].output_);
+    EXPECT_TRUE(storage->getLoggingInfo()[0].destinations_[0].flush_);
+
+    ASSERT_TRUE(config->get(0)->get("output-options"));
+    ASSERT_FALSE(config->get(0)->get("output_options"));
+}
+
+// This test checks that specifying both output-options and deprecated parameter
+// output_options is not accepted.
+TEST_F(LoggingTest, parsingErrorOutputOptions) {
+
+    const char* config_txt =
+    "{ \"loggers\": ["
+    "    {"
+    "        \"name\": \"kea\","
+    "        \"output_options\": ["
+    "            {"
+    "                \"output\": \"stdout\","
+    "                \"flush\": true"
+    "            }"
+    "        ],"
+    "        \"output-options\": ["
+    "            {"
+    "                \"output\": \"stdout\","
+    "                \"flush\": true"
+    "            }"
+    "        ],"
+    "        \"debuglevel\": 99,"
+    "        \"severity\": \"DEBUG\""
+    "    }"
+    "]}";
+
+    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");
+
+    ASSERT_EQ(1, config->size());
+    ASSERT_TRUE(config->get(0)->get("output_options"));
+    ASSERT_TRUE(config->get(0)->get("output-options"));
+
+    ASSERT_THROW_MSG(parser.parseConfiguration(config), BadValue, "Only one of "
+                     "'output-options' and 'output_options' may be specified.");
+
+    ASSERT_EQ(0, storage->getLoggingInfo().size());
+}
+
 // Check that LogConfigParser can parse configuration that
 // lacks a severity entry.
 TEST_F(LoggingTest, parsingNoSeverity) {