]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
dnsdist: Structured logging for Lua bindings
authorRemi Gacogne <remi.gacogne@powerdns.com>
Thu, 18 Dec 2025 11:36:42 +0000 (12:36 +0100)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Mon, 19 Jan 2026 09:58:29 +0000 (10:58 +0100)
Signed-off-by: Remi Gacogne <remi.gacogne@powerdns.com>
pdns/dnsdistdist/dnsdist-lua-bindings-dnscrypt.cc
pdns/dnsdistdist/dnsdist-lua-bindings-network.cc
pdns/dnsdistdist/dnsdist-lua-bindings-packetcache.cc
pdns/dnsdistdist/dnsdist-lua-bindings.cc
pdns/dnsdistdist/dnsdist-lua-configuration-items.cc

index bd430542b8cb29fd850a8d613fe3819505ee3f3d..28460c5e3666287ea7218a3e1c9f281405751973 100644 (file)
@@ -118,7 +118,8 @@ void setupLuaBindingsDNSCrypt([[maybe_unused]] LuaContext& luaCtx, [[maybe_unuse
       }
     }
     catch (const std::exception& e) {
-      errlog("Error generating a DNSCrypt certificate: %s", e.what());
+      SLOG(errlog("Error generating a DNSCrypt certificate: %s", e.what()),
+           dnsdist::logging::getTopLogger()->error(Logr::Error, e.what(), "Error generating a DNSCrypt certificate"));
       g_outputBuffer = "Error generating a DNSCrypt certificate: " + string(e.what()) + "\n";
       return false;
     }
@@ -183,7 +184,8 @@ void setupLuaBindingsDNSCrypt([[maybe_unused]] LuaContext& luaCtx, [[maybe_unuse
       }
     }
     catch (const std::exception& e) {
-      errlog("Error generating a DNSCrypt certificate: %s", e.what());
+      SLOG(errlog("Error generating a DNSCrypt certificate: %s", e.what()),
+           dnsdist::logging::getTopLogger()->error(Logr::Error, e.what(), "Error generating a DNSCrypt certificate"));
       g_outputBuffer = "Error generating a DNSCrypt certificate: " + string(e.what()) + "\n";
     }
   });
@@ -213,7 +215,8 @@ void setupLuaBindingsDNSCrypt([[maybe_unused]] LuaContext& luaCtx, [[maybe_unuse
       g_outputBuffer = "Provider fingerprint is: " + DNSCryptContext::getProviderFingerprint(publicKey) + "\n";
     }
     catch (const std::exception& e) {
-      errlog("Error generating a DNSCrypt provider key: %s", e.what());
+      SLOG(errlog("Error generating a DNSCrypt provider key: %s", e.what()),
+           dnsdist::logging::getTopLogger()->error(Logr::Error, e.what(), "Error generating a DNSCrypt provider key"));
       g_outputBuffer = "Error generating a DNSCrypt provider key: " + string(e.what()) + "\n";
     }
 
@@ -238,7 +241,8 @@ void setupLuaBindingsDNSCrypt([[maybe_unused]] LuaContext& luaCtx, [[maybe_unuse
       g_outputBuffer = "Provider fingerprint is: " + DNSCryptContext::getProviderFingerprint(publicKey) + "\n";
     }
     catch (const std::exception& e) {
-      errlog("Error getting a DNSCrypt provider fingerprint: %s", e.what());
+      SLOG(errlog("Error getting a DNSCrypt provider fingerprint: %s", e.what()),
+           dnsdist::logging::getTopLogger()->error(Logr::Error, e.what(), "Error getting a DNSCrypt provider fingerprint"));
       g_outputBuffer = "Error getting a DNSCrypt provider fingerprint: " + string(e.what()) + "\n";
     }
   });
index 7f95f1865ef6263221a797a9b2055e28759b6409..e782a1996134b84ad7fcf69661daa7fe29a59036 100644 (file)
@@ -37,7 +37,8 @@ void setupLuaBindingsNetwork(LuaContext& luaCtx, bool client)
       return std::make_shared<dnsdist::NetworkEndpoint>(path);
     }
     catch (const std::exception& e) {
-      warnlog("Error connecting to network endpoint: %s", e.what());
+      SLOG(warnlog("Error connecting to network endpoint: %s", e.what()),
+           dnsdist::logging::getTopLogger()->error(Logr::Error, e.what(), "Error connecting to network endpoint"));
     }
     return std::shared_ptr<dnsdist::NetworkEndpoint>(nullptr);
   });
index 2ccfa5b01226d333385653f35cb21dffe8639a38..f3b20115b700c6f354f8bb9e7f10e8c39f1bfe7d 100644 (file)
@@ -90,7 +90,8 @@ void setupLuaBindingsPacketCache(LuaContext& luaCtx, bool client)
     checkAllParametersConsumed("newPacketCache", vars);
 
     if (maxEntries < settings.d_shardCount) {
-      warnlog("The number of entries (%d) in the packet cache is smaller than the number of shards (%d), decreasing the number of shards to %d", maxEntries, settings.d_shardCount, maxEntries);
+      SLOG(warnlog("The number of entries (%d) in the packet cache is smaller than the number of shards (%d), decreasing the number of shards to %d", maxEntries, settings.d_shardCount, maxEntries),
+           dnsdist::logging::getTopLogger()->withName("configuration")->info(Logr::Warning, "The number of entries in the packet cache is smaller than the number of shards, decreasing the number of shards to the number of entries", "number_of_entries", Logging::Loggable(maxEntries), "number_of_shards", Logging::Loggable(settings.d_shardCount)));
       g_outputBuffer += "The number of entries (" + std::to_string(maxEntries) + " in the packet cache is smaller than the number of shards (" + std::to_string(settings.d_shardCount) + "), decreasing the number of shards to " + std::to_string(maxEntries);
       settings.d_shardCount = maxEntries;
     }
index 11dab9752d2373acb79fb7ed2dad9ef823299c0f..953d80aeedf946dcf7a8a89953c949b9b7a7f6ad 100644 (file)
 void setupLuaBindingsLogging(LuaContext& luaCtx)
 {
   luaCtx.writeFunction("vinfolog", [](const string& arg) {
-    vinfolog("%s", arg);
+    VERBOSESLOG(infolog("%s", arg),
+                dnsdist::logging::getTopLogger()->withName("lua-message")->info(Logr::Info, arg));
   });
   luaCtx.writeFunction("infolog", [](const string& arg) {
-    infolog("%s", arg);
+    SLOG(infolog("%s", arg),
+         dnsdist::logging::getTopLogger()->withName("lua-message")->info(Logr::Info, arg));
   });
   luaCtx.writeFunction("errlog", [](const string& arg) {
-    errlog("%s", arg);
+    SLOG(errlog("%s", arg),
+         dnsdist::logging::getTopLogger()->withName("lua-message")->info(Logr::Error, arg));
   });
   luaCtx.writeFunction("warnlog", [](const string& arg) {
-    warnlog("%s", arg);
+    SLOG(warnlog("%s", arg),
+         dnsdist::logging::getTopLogger()->withName("lua-message")->info(Logr::Warning, arg));
   });
   luaCtx.writeFunction("show", [](const string& arg) {
     g_outputBuffer += arg;
@@ -1092,7 +1096,8 @@ void setupLuaBindings(LuaContext& luaCtx, bool client, bool configCheck)
           callback(resolvedHostname, result);
         }
         catch (const std::exception& exp) {
-          vinfolog("Error during execution of getAddressInfo callback: %s", exp.what());
+          VERBOSESLOG(infolog("Error during execution of getAddressInfo callback: %s", exp.what()),
+                      dnsdist::logging::getTopLogger()->error(Logr::Error, exp.what(), "Error during execution of getAddressInfo callback"));
         }
         // this _needs_ to be done while we are holding the lock,
         // otherwise the destructor will corrupt the stack
index 82d810dd13528d437048d2c76499e0097512b8a9..1a4afe5989ec17ef29f755d0ec4d567884182e5c 100644 (file)
@@ -100,12 +100,15 @@ static const std::map<std::string, UnsignedIntegerConfigurationItems> s_unsigned
   {"setProxyProtocolMaximumPayloadSize", {[](dnsdist::configuration::RuntimeConfiguration& config, uint64_t newValue) { config.d_proxyProtocolMaximumSize = std::max(static_cast<uint64_t>(16), newValue); }, std::numeric_limits<uint32_t>::max()}},
   {"setPayloadSizeOnSelfGeneratedAnswers", {[](dnsdist::configuration::RuntimeConfiguration& config, uint64_t newValue) {
     if (newValue < 512) {
-      warnlog("setPayloadSizeOnSelfGeneratedAnswers() is set too low, using 512 instead!");
+      SLOG(warnlog("setPayloadSizeOnSelfGeneratedAnswers() is set too low, using 512 instead!"),
+           dnsdist::logging::getTopLogger()->withName("configuration")->info(Logr::Warning, "Value passed to setPayloadSizeOnSelfGeneratedAnswers() is set too low, using 512 instead", "value", Logging::Loggable(newValue)));
+
       g_outputBuffer = "setPayloadSizeOnSelfGeneratedAnswers() is set too low, using 512 instead!";
       newValue = 512;
     }
     if (newValue > dnsdist::configuration::s_udpIncomingBufferSize) {
-      warnlog("setPayloadSizeOnSelfGeneratedAnswers() is set too high, capping to %d instead!", dnsdist::configuration::s_udpIncomingBufferSize);
+      SLOG(warnlog("setPayloadSizeOnSelfGeneratedAnswers() is set too high, capping to %d instead!", dnsdist::configuration::s_udpIncomingBufferSize),
+           dnsdist::logging::getTopLogger()->withName("configuration")->info(Logr::Warning, "Value passed to setPayloadSizeOnSelfGeneratedAnswers() is set too high, capping", "value", Logging::Loggable(newValue), "cap", Logging::Loggable(dnsdist::configuration::s_udpIncomingBufferSize)));
       g_outputBuffer = "setPayloadSizeOnSelfGeneratedAnswers() is set too high, capping to " + std::to_string(dnsdist::configuration::s_udpIncomingBufferSize) + " instead";
       newValue = dnsdist::configuration::s_udpIncomingBufferSize;
     }
@@ -211,7 +214,8 @@ void setupConfigurationItems(LuaContext& luaCtx)
       }
       catch (const std::exception& exp) {
         g_outputBuffer = name + " cannot be used at runtime!\n";
-        errlog("%s cannot be used at runtime!", name);
+        SLOG(errlog("%s cannot be used at runtime!", name),
+             dnsdist::logging::getTopLogger()->withName("configuration")->info(Logr::Error, "The " + name + " directive cannot be used at runtime"));
       }
     });
   }
@@ -226,7 +230,8 @@ void setupConfigurationItems(LuaContext& luaCtx)
       }
       catch (const std::exception& exp) {
         g_outputBuffer = name + " cannot be used at runtime!\n";
-        errlog("%s cannot be used at runtime!", name);
+        SLOG(errlog("%s cannot be used at runtime!", name),
+             dnsdist::logging::getTopLogger()->withName("configuration")->info(Logr::Error, "The " + name + " directive cannot be used at runtime"));
       }
     });
   }
@@ -234,7 +239,8 @@ void setupConfigurationItems(LuaContext& luaCtx)
     luaCtx.writeFunction(item.first, [&name = item.first, &item = item.second](double value) {
       if (value != 0 && value < item.minimumValue) {
         g_outputBuffer = "Invalid value passed to " + name + "()!\n";
-        errlog("Invalid value passed to %s()!", name);
+        SLOG(errlog("Invalid value passed to %s()!", name),
+             dnsdist::logging::getTopLogger()->withName("configuration")->info(Logr::Error, "Invalid value passed to " + name, "value", Logging::Loggable(value)));
         return;
       }
 
@@ -245,7 +251,8 @@ void setupConfigurationItems(LuaContext& luaCtx)
       }
       catch (const std::exception& exp) {
         g_outputBuffer = name + " cannot be used at runtime!\n";
-        errlog("%s cannot be used at runtime!", name);
+        SLOG(errlog("%s cannot be used at runtime!", name),
+             dnsdist::logging::getTopLogger()->withName("configuration")->info(Logr::Error, "The " + name + " directive cannot be used at runtime"));
       }
       setLuaSideEffect();
     });