]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
dnsdist: Enable structured logging by default
authorRemi Gacogne <remi.gacogne@powerdns.com>
Mon, 19 Jan 2026 11:24:04 +0000 (12:24 +0100)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Mon, 19 Jan 2026 11:24:04 +0000 (12:24 +0100)
Signed-off-by: Remi Gacogne <remi.gacogne@powerdns.com>
pdns/dnsdistdist/dnsdist-configuration.hh
pdns/dnsdistdist/dnsdist-settings-definitions.yml
pdns/dnsdistdist/dnsdist.cc
pdns/dnsdistdist/docs/manpages/dnsdist.1.rst
pdns/dnsdistdist/docs/reference/config.rst
regression-tests.dnsdist/dnsdisttests.py
regression-tests.dnsdist/test_ConfigurationUpdates.py
regression-tests.dnsdist/test_DOH.py
regression-tests.dnsdist/test_IncomingProtocol.py
regression-tests.dnsdist/test_Lua.py
regression-tests.dnsdist/test_Yaml.py

index 9fc3987bbf904bfc3fddfecb2bf59290e0883fde..eefdcf308f53197d0dd95713ab30faea9b26cb22 100644 (file)
@@ -116,7 +116,7 @@ struct ImmutableConfiguration
   bool d_ringsRecordResponses{true};
   bool d_snmpEnabled{false};
   bool d_snmpTrapsEnabled{false};
-  bool d_structuredLogging{false};
+  bool d_structuredLogging{true};
   bool d_structuredLoggingUseServerID{false};
 };
 
index cd1e1b68abac5bacec57e043d470c9a9963c9059..fc65b7775150b901d850dfd28cc593c5a090b7a1 100644 (file)
@@ -1777,7 +1777,7 @@ structured_logging:
   parameters:
     - name: "enabled"
       type: "bool"
-      default: "false"
+      default: "true"
       description: |
         Set whether log messages should be in structured-logging format."
       changes:
index 5a7f41636c41a710413e4abf8de5038f3d9c818a..6e773d4816442871df9720a19f41ea02ef64fcea 100644 (file)
@@ -2968,7 +2968,7 @@ struct CommandLineParameters
   bool checkConfig{false};
   bool beClient{false};
   bool beSupervised{false};
-  bool useStructuredLogging{false};
+  bool useStructuredLogging{true};
 };
 
 static void usage()
@@ -3001,7 +3001,7 @@ static void usage()
   cout << "--disable-syslog                      Don't log to syslog, only to stdout\n";
   cout << "                                      (use with e.g. systemd)\n";
   cout << "--log-timestamps                      Prepend timestamps to messages logged to stdout\n";
-  cout << "--structured-logging                  Enable structured logging\n";
+  cout << "--structured-logging true|false       Whether to enable structured logging\n";
   cout << "--structured-logging-backend BACKEND  The backend to use when structured logging is enabled\n";
   cout << "                                      Supported values are 'default', 'json' and 'systemd-journal'\n";
   cout << "-u,--uid uid                          Change the process user ID after binding sockets\n";
@@ -3194,7 +3194,7 @@ static void parseParameters(int argc, char** argv, CommandLineParameters& cmdLin
                                                 {"local", required_argument, nullptr, 'l'},
                                                 {"log-timestamps", no_argument, nullptr, 4},
                                                 {"setkey", required_argument, nullptr, 'k'},
-                                                {"structured-logging", no_argument, nullptr, 's'},
+                                                {"structured-logging", required_argument, nullptr, 's'},
                                                 {"structured-logging-backend", required_argument, nullptr, 5},
                                                 {"supervised", no_argument, nullptr, 3},
                                                 {"uid", required_argument, nullptr, 'u'},
@@ -3273,7 +3273,7 @@ static void parseParameters(int argc, char** argv, CommandLineParameters& cmdLin
       cmdLine.locals.push_back(boost::trim_copy(string(optarg)));
       break;
     case 's':
-      cmdLine.useStructuredLogging = true;
+      cmdLine.useStructuredLogging = (boost::to_lower_copy(std::string(optarg)) == "true");
       break;
     case 'u':
       cmdLine.uid = optarg;
index 59164abb3bf6c4be44528630458e34685c35985e..7221ce5bede189aef73c5a74658be7d89a121388 100644 (file)
@@ -70,7 +70,7 @@ Options
 --disable-syslog                        Disable logging to syslog. Use this when running inside a supervisor
                                         that handles logging (like systemd).
 --log-timestamps                        Prepend timestamps to messages logged to standard out.
---structured-logging                    Enable structured logging.
+--structured-logging <true|false>       Whether to enable structured logging.
 --structured-logging-backend <backend>  The backend to use when structured logging is enabled.
                                         Supported values are 'default', 'json' and 'systemd-journal'.
 -u, --uid <uid>                         Change the process user to *uid* after binding sockets. *uid* can be
index 793e751e67e691f517a4b9e4144dc92aca817ed1..b2bf9e5ebd032cbf874b8668eed42a2163dcf871 100644 (file)
@@ -1406,8 +1406,9 @@ Status, Statistics and More
     The ``backend`` option has been added.
     The ``setInstanceFromServerID`` option has been added
     The ``levelPrefix`` option has no longer any effect because it was confusing. The log level is now always logged as ``level`` and the syslog priority, if any, as ``priority`` in all backends except the default one where it is named ``prio``
+    Structured logging is now enabled by default.
 
-  Set whether log messages should be in structured-logging format. This is turned off by default. See :doc:`../advanced/structured-logging-dictionary` for more details.
+  Set whether log messages should be in structured-logging format. This is enabled by default since 2.1.0. See :doc:`../advanced/structured-logging-dictionary` for more details.
 
   The resulting format looks like this (when timestamps are enabled via ``--log-timestamps`` and ``timeFormat="ISO8601"``)::
 
index 400eb92e3159b94b00b65876e914971921542f7a..a53c58092d710cda8ad12e7a9587f3e31544f134 100644 (file)
@@ -105,6 +105,7 @@ class DNSDistTest(AssertEqualDNSMessageMixin, unittest.TestCase):
     _UDPResponder = None
     _TCPResponder = None
     _extraStartupSleep = 0
+    _disableStructuredLoggingOnCL = False
     _dnsDistPort = pickAvailablePort()
     _consolePort = pickAvailablePort()
     _testServerPort = pickAvailablePort()
@@ -182,6 +183,11 @@ class DNSDistTest(AssertEqualDNSMessageMixin, unittest.TestCase):
 
         if cls._verboseMode:
             dnsdistcmd.append('-v')
+
+        if cls._disableStructuredLoggingOnCL:
+            dnsdistcmd.append('--structured-logging')
+            dnsdistcmd.append('false')
+
         if cls._sudoMode:
             preserve_env_values = ['LD_LIBRARY_PATH', 'LLVM_PROFILE_FILE']
             for value in preserve_env_values:
@@ -206,11 +212,17 @@ class DNSDistTest(AssertEqualDNSMessageMixin, unittest.TestCase):
         else:
             if cls._checkConfigExpectedOutput is not None:
                 expectedOutput = cls._checkConfigExpectedOutput
-            else:
-                expectedOutput = ('Configuration \'%s\' OK!\n' % (confFile)).encode()
-
-            if not cls._verboseMode and output != expectedOutput:
-                raise AssertionError('dnsdist --check-config failed: %s (expected %s)' % (output, expectedOutput))
+                if not cls._verboseMode and output != expectedOutput:
+                  raise AssertionError('dnsdist --check-config failed: %s (expected %s)' % (output, expectedOutput))
+            elif not cls._verboseMode:
+                if not cls._disableStructuredLoggingOnCL:
+                    expectedPrefix = b'msg="Configuration OK" subsystem="setup" level="0" prio="Info" ts="'
+                    if not output.startswith(expectedPrefix):
+                        raise AssertionError('dnsdist --check-config failed: %s (expected prefix %s)' % (output, expectedPrefix))
+                else:
+                    expectedOutput = ('Configuration \'%s\' OK!\n' % (confFile)).encode()
+                    if output != expectedOutput:
+                        raise AssertionError('dnsdist --check-config failed: %s (expected %s)' % (output, expectedOutput))
 
         logFile = os.path.join('configs', 'dnsdist_%s.log' % (cls.__name__))
         with open(logFile, 'w') as fdLog:
index d0414cc0f30843de52c1c2c7f4ef26ed1c8d3711..56c6ccb03801e24929edd1aed69c62adcd638870 100644 (file)
@@ -7,6 +7,10 @@ import extendederrors
 
 class TestConfigurationUpdates(DNSDistTest):
     _yaml_config_template = """---
+logging:
+  structured:
+    enabled: false
+
 console:
   listen_address: "127.0.0.1:%d"
   key: "%s"
index be16466bfaf6978827675856002ccaa1e67df27e..e38e410c84c3d3de1a69794a262ca9dad95437fa 100644 (file)
@@ -1144,9 +1144,7 @@ class DOHOverHTTP(object):
 
 class TestDOHOverHTTPNGHTTP2(DOHOverHTTP, DNSDistDOHTest):
     _dohLibrary = 'nghttp2'
-    _checkConfigExpectedOutput = b"""No certificate provided for DoH endpoint 127.0.0.1:%d, running in DNS over HTTP mode instead of DNS over HTTPS
-Configuration 'configs/dnsdist_TestDOHOverHTTPNGHTTP2.conf' OK!
-""" % (DOHOverHTTP._dohServerPort)
+    _checkConfigExpectedOutputPrefix = b'msg="No certificate provided for DoH frontend, running in DNS over HTTP mode instead of DNS over HTTPS"'
 
 class DOHWithCache(object):
 
index 71de3230549f798b19fbd588b9fc3235ad38fdf0..d221aae63a51c192af821ad477907f4ec7826604 100644 (file)
@@ -59,6 +59,9 @@ class IncomingProtocolLuaConfig(DNSDistTest, IncomingProtocol):
 
 class IncomingProtocolYAMLConfig(DNSDistTest, IncomingProtocol):
     _yaml_config_template = """
+logging:
+  structured:
+    enabled: false
 backends:
   - address: "127.0.0.1:%d"
     protocol: Do53
index 2a33a7084d1a52391eeb9bdd7ddc214a76a7681a..d390bf7b0d2369bb9fe3351b6ca88c1569f5f03d 100644 (file)
@@ -95,6 +95,7 @@ class TestLuaDNSHeaderBindings(DNSDistTest):
 
 class TestLuaFrontendBindings(DNSDistTest):
     _config_template = """
+    setStructuredLogging(false)
     newServer{address="127.0.0.1:%d"}
 
     -- check that all these methods return nil on a non-existing entry
index d95bfef32d860a7d2a8eb6e71f45d4fdf681afba..e98a084c962d43d27b0d27619b35cf9317b11a51 100644 (file)
@@ -528,6 +528,10 @@ query_rules:
 class TestYamlUnknownSelectorName(DNSDistTest):
 
     _yaml_config_template = """---
+logging:
+  structured:
+    enabled: false
+
 binds:
   - listen_address: "127.0.0.1:%d"
     protocol: Do53
@@ -552,6 +556,9 @@ query_rules:
 """
     _yaml_config_params = ['_dnsDistPort', '_testServerPort']
     _config_params = []
+    # we need this because the error is triggered during the parsing of the YAML configuration,
+    # too early for the logging for the logging configuration to have been applied
+    _disableStructuredLoggingOnCL = True
 
     def testFailToStart(self):
         """
@@ -580,6 +587,10 @@ query_rules:
 class TestYamlUnknownPolicyName(DNSDistTest):
 
     _yaml_config_template = """---
+logging:
+  structured:
+    enabled: false
+
 binds:
   - listen_address: "127.0.0.1:%d"
     protocol: Do53