]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
More smart logging of iterables and inline a few methods
authorOtto Moerbeek <otto.moerbeek@open-xchange.com>
Wed, 18 May 2022 15:38:32 +0000 (17:38 +0200)
committerOtto Moerbeek <otto.moerbeek@open-xchange.com>
Thu, 19 May 2022 08:55:32 +0000 (10:55 +0200)
pdns/logging.hh
pdns/recursordist/logging.cc
pdns/recursordist/rec-main.cc
pdns/reczones.cc

index 75a7ac48b7f4e1a416e977129c7a8b65aa3e51cd..01e0d7a685f15efc5f1b793f65ea51eba212d377 100644 (file)
@@ -66,17 +66,46 @@ struct Loggable : public Logr::Loggable
   }
 };
 template <>
-std::string Loggable<DNSName>::to_string() const;
-template <>
-std::string Loggable<ComboAddress>::to_string() const;
-template <>
-std::string Loggable<std::string>::to_string() const;
+inline std::string Loggable<DNSName>::to_string() const
+{
+  return _t.toLogString();
+}
 template <>
-std::string Loggable<std::vector<std::string>>::to_string() const;
+inline std::string Loggable<ComboAddress>::to_string() const
+{
+  return _t.toLogString();
+}
 template <>
-std::string Loggable<std::set<int>>::to_string() const;
+inline std::string Loggable<std::string>::to_string() const
+{
+  return _t;
+}
 
-// Loggable<std::string>::Loggable(const std::string& v): _t(v) {}
+template <typename T>
+struct IterLoggable : public Logr::Loggable
+{
+  const T& _t1;
+  const T& _t2;
+  IterLoggable(const T& v1, const T& v2) :
+    _t1(v1), _t2(v2)
+  {
+  }
+  std::string to_string() const
+  {
+    std::ostringstream oss;
+    bool first = true;
+    for (auto i = _t1; i != _t2; i++) {
+      if (!first) {
+        oss << ' ';
+      }
+      else {
+        first = false;
+      }
+      oss << *i;
+    }
+    return oss.str();
+  }
+};
 
 typedef void (*EntryLogger)(const Entry&);
 
index 6ac2bcc4dc7d4d4e3fe6fd9d7d7f3133b1b9b6e4..5cfef1752c0de7f353d2fe7575e741a8a5e2a2b0 100644 (file)
@@ -106,60 +106,6 @@ std::shared_ptr<Logr::Logger> Logger::withValues(const std::map<std::string, std
   return res;
 }
 
-template struct Loggable<DNSName>;
-template struct Loggable<ComboAddress>;
-template struct Loggable<std::string>;
-template struct Loggable<size_t>;
-
-template <>
-std::string Loggable<DNSName>::to_string() const
-{
-  return _t.toLogString();
-}
-template <>
-std::string Loggable<ComboAddress>::to_string() const
-{
-  return _t.toLogString();
-}
-template <>
-std::string Loggable<std::string>::to_string() const
-{
-  return _t;
-}
-template <>
-std::string Loggable<std::vector<std::string>>::to_string() const
-{
-  std::ostringstream oss;
-  bool first = true;
-  for (const auto& e : _t) {
-    if (!first) {
-      oss << ' ';
-    }
-    else {
-      first = false;
-    }
-    oss << e;
-  }
-  return oss.str();
-}
-
-template <>
-std::string Loggable<std::set<int>>::to_string() const
-{
-  std::ostringstream oss;
-  bool first = true;
-  for (const auto& e : _t) {
-    if (!first) {
-      oss << ' ';
-    }
-    else {
-      first = false;
-    }
-    oss << e;
-  }
-  return oss.str();
-}
-
 std::shared_ptr<Logr::Logger> Logger::withName(const std::string& name) const
 {
   std::shared_ptr<Logger> res;
index 06e4c86a013119f03baf506271bbe9bbe44a3c06..a1ee629a87ee105ba9e167f508b7f9e4abc9b593 100644 (file)
@@ -172,7 +172,7 @@ static void setCPUMap(const std::map<unsigned int, std::set<int>>& cpusMap, unsi
       g_log << Logger::Info << endl;
     }
     else {
-      log->info(Logr::Info,  "CPU affinity has been set", "thread", Logging::Loggable(n), "cpumap", Logging::Loggable(cpuMapping->second));
+      log->info(Logr::Info,  "CPU affinity has been set", "thread", Logging::Loggable(n), "cpumap", Logging::IterLoggable(cpuMapping->second.begin(), cpuMapping->second.end()));
     }
   }
   else {
@@ -184,7 +184,7 @@ static void setCPUMap(const std::map<unsigned int, std::set<int>>& cpusMap, unsi
       g_log << Logger::Info << ' ' << strerror(rc) << endl;
     }
     else {
-      log->info(Logr::Warning, "Error setting CPU affinity", "thread", Logging::Loggable(n), "cpumap", Logging::Loggable(cpuMapping->second));
+      log->error(Logr::Warning, rc, "Error setting CPU affinity", "thread", Logging::Loggable(n), "cpumap", Logging::IterLoggable(cpuMapping->second.begin(), cpuMapping->second.end()));
     }
   }
 }
@@ -993,7 +993,7 @@ static std::shared_ptr<NetmaskGroup> parseACL(const std::string& aclFile, const
       g_log << Logger::Info << endl;
     }
     else {
-      log->info(Logr::Info, "Setting access control", "acl", Logging::Loggable(aclSetting), "addresses", Logging::Loggable(ips));
+      log->info(Logr::Info, "Setting access control", "acl", Logging::Loggable(aclSetting), "addresses", Logging::IterLoggable(ips.begin(), ips.end()));
     }
   }
 
@@ -1319,7 +1319,7 @@ static int serviceMain(int argc, char* argv[], std::shared_ptr<Logr::Logger>& lo
       g_log << Logger::Warning << endl;
     }
     else {
-      log->info(Logr::Notice, "Will not send queries to", "addresses", Logging::Loggable(ips));
+      log->info(Logr::Notice, "Will not send queries to", "addresses", Logging::IterLoggable(ips.begin(), ips.end()));
     }
   }
 
index 091a706bf3f3a779e10332de66479b270fb13697..24ca8cf4862ac7f42a841cca505185efc73d16da 100644 (file)
@@ -317,7 +317,7 @@ static void convertServersForAD(const std::string& zone, const std::string& inpu
       g_log << endl;
     }
     else {
-      log->info(Logr::Info, "Redirecting queries", "zone", Logging::Loggable(zone), "recursion", Logging::Loggable(ad.d_rdForward), "addresses", Logging::Loggable(addresses));
+      log->info(Logr::Info, "Redirecting queries", "zone", Logging::Loggable(zone), "recursion", Logging::Loggable(ad.d_rdForward), "addresses", Logging::IterLoggable(addresses.begin(), addresses.end()));
     }
   }
 }
@@ -548,7 +548,7 @@ std::tuple<std::shared_ptr<SyncRes::domainmap_t>, std::shared_ptr<notifyset_t>>
     ifstream ifs(fname.c_str());
     if (!ifs) {
       SLOG(g_log << Logger::Warning << "Could not open " << fname << " for reading" << endl,
-           log->error(Logr::Warning,  "Could not open file for reading", "file", Logging::Loggable(fname)));
+           log->error(Logr::Warning, "Could not open file for reading", "file", Logging::Loggable(fname)));
     }
     else {
       string searchSuffix = ::arg()["export-etc-hosts-search-suffix"];