]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
rec: for structured logging always log addresses including port
authorOtto Moerbeek <otto.moerbeek@open-xchange.com>
Fri, 3 Nov 2023 08:42:06 +0000 (09:42 +0100)
committerOtto Moerbeek <otto.moerbeek@open-xchange.com>
Fri, 3 Nov 2023 08:42:06 +0000 (09:42 +0100)
As documented. The way this is done is by defined a specific
log function if SL is used. Could potentially be used for other
cases.

pdns/iputils.hh
pdns/logging.hh

index c5fbf164253cf2a0d17cfdcefe60b92ca85464c9..f61fed840223f2a77478abbbf1c345d2ac4dc23a 100644 (file)
@@ -332,6 +332,11 @@ union ComboAddress {
     return toStringWithPortExcept(53);
   }
 
+  [[nodiscard]] string toStructuredLogString() const
+  {
+    return toStringWithPort();
+  }
+
   string toByteString() const
   {
     if (isIPv4()) {
index 12c46ed581d112afae3c571867b3a5b7a6ff0812..dfff184efe463d7e188dbed9bafa4508850c7f69 100644 (file)
@@ -69,7 +69,7 @@ struct is_to_string_available<T, std::void_t<decltype(std::to_string(std::declva
 {
 };
 
-// Same mechanism for t.toLogString()
+// Same mechanism for t.toLogString() and t.toStucturedLogString()
 template <typename T, typename = void>
 struct is_toLogString_available : std::false_type
 {
@@ -80,6 +80,16 @@ struct is_toLogString_available<T, std::void_t<decltype(std::declval<T>().toLogS
 {
 };
 
+template <typename T, typename = void>
+struct is_toStructuredLogString_available : std::false_type
+{
+};
+
+template <typename T>
+struct is_toStructuredLogString_available<T, std::void_t<decltype(std::declval<T>().toStructuredLogString())>> : std::true_type
+{
+};
+
 template <typename T, typename = void>
 struct is_toString_available : std::false_type
 {
@@ -103,6 +113,9 @@ struct Loggable : public Logr::Loggable
     if constexpr (std::is_same_v<T, std::string>) {
       return _t;
     }
+    else if constexpr (is_toStructuredLogString_available<T>::value) {
+      return _t.toStructuredLogString();
+    }
     else if constexpr (is_toLogString_available<T>::value) {
       return _t.toLogString();
     }