]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Add pdnslog to Lua configuration scripts 6848/head
authorChris Hofstaedtler <chris.hofstaedtler@deduktiva.com>
Fri, 10 Aug 2018 16:26:23 +0000 (18:26 +0200)
committerChris Hofstaedtler <chris.hofstaedtler@deduktiva.com>
Fri, 10 Aug 2018 16:26:23 +0000 (18:26 +0200)
pdns/rec-lua-conf.cc
pdns/recursordist/docs/lua-config/index.rst

index d8ca13de2e9488b2147812b9edc9caf44b4e3696..9db2afa6317bd543a809d27724b593082375ef16 100644 (file)
@@ -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<int> loglevel) { g_log << (Logger::Urgency)loglevel.get_value_or(Logger::Warning) << msg<<endl; });
+  std::unordered_map<string, std::unordered_map<string, int>> pdns_table;
+  pdns_table["loglevels"] = std::unordered_map<string, int>{
+    {"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"
index 4899b55dc7e480bff95cccc8aa6fa8ef3bb431a8..7c65d8e9efd322d98749193a408207862a82fe94 100644 (file)
@@ -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.