From c2cc36d8c38d4e4f353d027ba760f2c8e77e6c84 Mon Sep 17 00:00:00 2001 From: Chris Hofstaedtler Date: Fri, 10 Aug 2018 18:26:23 +0200 Subject: [PATCH] Add pdnslog to Lua configuration scripts --- pdns/rec-lua-conf.cc | 15 +++++++++++++++ pdns/recursordist/docs/lua-config/index.rst | 2 ++ 2 files changed, 17 insertions(+) diff --git a/pdns/rec-lua-conf.cc b/pdns/rec-lua-conf.cc index d8ca13de2e..9db2afa631 100644 --- a/pdns/rec-lua-conf.cc +++ b/pdns/rec-lua-conf.cc @@ -132,6 +132,21 @@ void loadRecursorLuaConfig(const std::string& fname, luaConfigDelayedThreads& de auto luaconfsLocal = g_luaconfs.getLocal(); lci.generation = luaconfsLocal->generation + 1; + // pdnslog here is compatible with pdnslog in lua-base4.cc. + Lua.writeFunction("pdnslog", [](const std::string& msg, boost::optional loglevel) { g_log << (Logger::Urgency)loglevel.get_value_or(Logger::Warning) << msg<> pdns_table; + pdns_table["loglevels"] = std::unordered_map{ + {"Alert", LOG_ALERT}, + {"Critical", LOG_CRIT}, + {"Debug", LOG_DEBUG}, + {"Emergency", LOG_EMERG}, + {"Info", LOG_INFO}, + {"Notice", LOG_NOTICE}, + {"Warning", LOG_WARNING}, + {"Error", LOG_ERR} + }; + Lua.writeVariable("pdns", pdns_table); + Lua.writeFunction("clearSortlist", [&lci]() { lci.sortlist.clear(); }); /* we can get: "1.2.3.4" diff --git a/pdns/recursordist/docs/lua-config/index.rst b/pdns/recursordist/docs/lua-config/index.rst index 4899b55dc7..7c65d8e9ef 100644 --- a/pdns/recursordist/docs/lua-config/index.rst +++ b/pdns/recursordist/docs/lua-config/index.rst @@ -9,3 +9,5 @@ Since version 4.0.0, the PowerDNS Recursor supports additional configuration opt sortlist protobuf rpz + +In addition, :func:`pdnslog` together with ``pdns.loglevels`` is also supported in the Lua configuration file. -- 2.47.2