Add pdnslog to Lua configuration scripts
authorChris Hofstaedtler <chris.hofstaedtler@deduktiva.com>
Fri, 10 Aug 2018 16:26:23 +0000 (18:26 +0200)
committerChris Hofstaedtler <zeha@debian.org>
Sun, 9 Sep 2018 19:29:51 +0000 (20:29 +0100)
Gbp-Pq: Name 0001-Add-pdnslog-to-Lua-configuration-scripts.patch

rec-lua-conf.cc

index e68836f5b0002ad787a0f30e0e272bcf19b5c72b..d25f0e9878943fca443716a953f5dddbfecf131f 100644 (file)
@@ -96,6 +96,21 @@ void loadRecursorLuaConfig(const std::string& fname, bool checkOnly)
 
   auto luaconfsLocal = g_luaconfs.getLocal();
 
+  // pdnslog here is compatible with pdnslog in lua-base4.cc.
+  Lua.writeFunction("pdnslog", [](const std::string& msg, boost::optional<int> loglevel) { L << (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"