]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Hook up the loglevel to the ixfrdist webserver
authorPieter Lexis <pieter.lexis@powerdns.com>
Thu, 14 Feb 2019 11:33:37 +0000 (12:33 +0100)
committerPieter Lexis <pieter.lexis@powerdns.com>
Thu, 14 Feb 2019 13:01:59 +0000 (14:01 +0100)
docs/manpages/ixfrdist.yml.5.rst
pdns/Makefile.am
pdns/ixfrdist-web.cc
pdns/ixfrdist-web.hh
pdns/ixfrdist.cc
pdns/ixfrdist.example.yml

index 6ad3fd132f80342f65dfb0a4e3ac114c7e1e6138..6e9ffd0f2e7d5f821d6348533a17324d9c0b48ff 100644 (file)
@@ -108,6 +108,14 @@ Options
   Entries without a netmask will be interpreted as a single address.
   By default, this list is set to ``127.0.0.0/8`` and ``::1/128``.
 
+:webserver-loglevel:
+  How much the webserver should log: 'none', 'normal' or 'detailed'.
+  When logging, each log-line contains the UUID of the request, this allows finding errors caused by certain requests.
+  With 'none', nothing is logged except for errors.
+  With 'normal' (the default), one line per request is logged in the style of the common log format::
+    [NOTICE] [webserver] 46326eef-b3ba-4455-8e76-15ec73879aa3 127.0.0.1:57566 "GET /metrics HTTP/1.1" 200 1846
+  with 'detailed', the full requests and responses (including headers) are logged along with the regular log-line from 'normal'.
+
 See also
 --------
 
index a2870326a3ade28d60afaa3d50537f3434df29d5..e72a34db4f330a8bcbcda6ad2b8445c975a36e57 100644 (file)
@@ -640,8 +640,8 @@ ixfrdist_SOURCES = \
        statbag.cc \
        threadname.hh threadname.cc \
        tsigverifier.cc tsigverifier.hh \
-       uuid-utils.hh uuid-utils.cc \
        unix_utility.cc \
+       uuid-utils.hh uuid-utils.cc \
        webserver.hh webserver.cc \
        zoneparser-tng.cc
 
index 01d2505d8ffd885481c24b1af15e1cdc37d26e54..485e720bcd8d2700be491a236f88feb1ed52b321 100644 (file)
 
 string doGetStats();
 
-IXFRDistWebServer::IXFRDistWebServer(const ComboAddress &listenAddress, const NetmaskGroup &acl) :
+IXFRDistWebServer::IXFRDistWebServer(const ComboAddress &listenAddress, const NetmaskGroup &acl, const string &loglevel) :
   d_ws(std::unique_ptr<WebServer>(new WebServer(listenAddress.toString(), listenAddress.getPort())))
 {
   d_ws->setACL(acl);
+  d_ws->setLogLevel(loglevel);
   d_ws->registerWebHandler("/metrics", boost::bind(&IXFRDistWebServer::getMetrics, this, _1, _2));
   d_ws->bind();
 }
index 580e976344332b3d0a577bf89c36ccc8541de766..e1c1734cc39b14e28d546cb8b2f7095a07091381 100644 (file)
@@ -26,7 +26,7 @@
 class IXFRDistWebServer
 {
   public:
-    explicit IXFRDistWebServer(const ComboAddress &listenAddress, const NetmaskGroup &acl);
+    explicit IXFRDistWebServer(const ComboAddress &listenAddress, const NetmaskGroup &acl, const string &loglevel);
     void go();
 
   private:
index 1ba8ffed0c0213ca501fbb887e5c0e65b2777cc7..5331d172d12566896fdf2cf036f473a226d6b0cc 100644 (file)
@@ -1125,6 +1125,16 @@ static bool parseAndCheckConfig(const string& configpath, YAML::Node& config) {
     }
   }
 
+  if (config["webserver-loglevel"]) {
+    try {
+      config["webserver-loglevel"].as<string>();
+    }
+    catch (const runtime_error &e) {
+      g_log<<Logger::Error<<"Unable to read 'webserver-loglevel' value: "<<e.what()<<endl;
+      retval = false;
+    }
+  }
+
   return retval;
 }
 
@@ -1267,8 +1277,18 @@ int main(int argc, char** argv) {
       }
     }
 
+    string loglevel = "normal";
+    if (config["webserver-loglevel"]) {
+      loglevel = config["webserver-loglevel"].as<string>();
+    }
+
     // Launch the webserver!
-    std::thread(&IXFRDistWebServer::go, IXFRDistWebServer(config["webserver-address"].as<ComboAddress>(), wsACL)).detach();
+    try {
+      std::thread(&IXFRDistWebServer::go, IXFRDistWebServer(config["webserver-address"].as<ComboAddress>(), wsACL, loglevel)).detach();
+    } catch (const PDNSException &e) {
+      g_log<<Logger::Error<<"Unable to start webserver: "<<e.reason<<endl;
+      had_error = true;
+    }
   }
 
   int newuid = 0;
index e7c8c4e7d723182f05f822b868d0f4604ca17de6..fef65d705c65933d24b20853cf6eda9ea58a5fea 100644 (file)
@@ -82,6 +82,12 @@ webserver-acl:
   - 127.0.0.0/8
   - ::1/128
 
+# How much the webserver should log: 'none', 'normal' or 'detailed'
+# With 'none', nothing is logged except for errors
+# With 'normal' (the default), one line per request is logged in the style of the common log format
+# with 'detailed', the full requests and responses (including headers) are logged
+webserver-loglevel: normal
+
 # The domains to redistribute, the 'master' and 'domains' keys are mandatory.
 # When no port is specified, 53 is used. When specifying ports for IPv6, use the
 # "bracket" notation: