From: Remi Gacogne Date: Thu, 18 Dec 2025 11:36:42 +0000 (+0100) Subject: dnsdist: Structured logging for Lua bindings X-Git-Tag: rec-5.4.0-beta1~33^2~32 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3bd76836c74043ddd5bf78612e9b679f2d55c938;p=thirdparty%2Fpdns.git dnsdist: Structured logging for Lua bindings Signed-off-by: Remi Gacogne --- diff --git a/pdns/dnsdistdist/dnsdist-lua-bindings-dnscrypt.cc b/pdns/dnsdistdist/dnsdist-lua-bindings-dnscrypt.cc index bd430542b8..28460c5e36 100644 --- a/pdns/dnsdistdist/dnsdist-lua-bindings-dnscrypt.cc +++ b/pdns/dnsdistdist/dnsdist-lua-bindings-dnscrypt.cc @@ -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"; } }); diff --git a/pdns/dnsdistdist/dnsdist-lua-bindings-network.cc b/pdns/dnsdistdist/dnsdist-lua-bindings-network.cc index 7f95f1865e..e782a19961 100644 --- a/pdns/dnsdistdist/dnsdist-lua-bindings-network.cc +++ b/pdns/dnsdistdist/dnsdist-lua-bindings-network.cc @@ -37,7 +37,8 @@ void setupLuaBindingsNetwork(LuaContext& luaCtx, bool client) return std::make_shared(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(nullptr); }); diff --git a/pdns/dnsdistdist/dnsdist-lua-bindings-packetcache.cc b/pdns/dnsdistdist/dnsdist-lua-bindings-packetcache.cc index 2ccfa5b012..f3b20115b7 100644 --- a/pdns/dnsdistdist/dnsdist-lua-bindings-packetcache.cc +++ b/pdns/dnsdistdist/dnsdist-lua-bindings-packetcache.cc @@ -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; } diff --git a/pdns/dnsdistdist/dnsdist-lua-bindings.cc b/pdns/dnsdistdist/dnsdist-lua-bindings.cc index 11dab9752d..953d80aeed 100644 --- a/pdns/dnsdistdist/dnsdist-lua-bindings.cc +++ b/pdns/dnsdistdist/dnsdist-lua-bindings.cc @@ -38,16 +38,20 @@ 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 diff --git a/pdns/dnsdistdist/dnsdist-lua-configuration-items.cc b/pdns/dnsdistdist/dnsdist-lua-configuration-items.cc index 82d810dd13..1a4afe5989 100644 --- a/pdns/dnsdistdist/dnsdist-lua-configuration-items.cc +++ b/pdns/dnsdistdist/dnsdist-lua-configuration-items.cc @@ -100,12 +100,15 @@ static const std::map s_unsigned {"setProxyProtocolMaximumPayloadSize", {[](dnsdist::configuration::RuntimeConfiguration& config, uint64_t newValue) { config.d_proxyProtocolMaximumSize = std::max(static_cast(16), newValue); }, std::numeric_limits::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(); });