Skip to content

Commit

Permalink
Hook up the loglevel to the ixfrdist webserver
Browse files Browse the repository at this point in the history
  • Loading branch information
pieterlexis committed Feb 14, 2019
1 parent a0badc0 commit f614922
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 4 deletions.
8 changes: 8 additions & 0 deletions docs/manpages/ixfrdist.yml.5.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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

This comment has been minimized.

Copy link
@gertvdijk

gertvdijk Apr 1, 2019

Contributor

@pieterlexis FYI I believe this introduced a Sphinx build warning.

WARNING: Literal block ends without a blank line; unexpected unindent.

Will fix in #7645.

with 'detailed', the full requests and responses (including headers) are logged along with the regular log-line from 'normal'.

See also
--------

Expand Down
2 changes: 1 addition & 1 deletion pdns/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 2 additions & 1 deletion pdns/ixfrdist-web.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,11 @@

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();
}
Expand Down
2 changes: 1 addition & 1 deletion pdns/ixfrdist-web.hh
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
22 changes: 21 additions & 1 deletion pdns/ixfrdist.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
Expand Down
6 changes: 6 additions & 0 deletions pdns/ixfrdist.example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit f614922

Please sign in to comment.