From: Chris Hofstaedtler Date: Fri, 10 Aug 2018 16:26:23 +0000 (+0200) Subject: Add pdnslog to Lua configuration scripts X-Git-Tag: dnsdist-1.3.3~127^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c2cc36d8c38d4e4f353d027ba760f2c8e77e6c84;p=thirdparty%2Fpdns.git Add pdnslog to Lua configuration scripts --- 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.