middleware/log: allows logging based on response classes (#325)

Add the ability to add a class of responses to be logged; success,
denial or error. The default is to log everything (all).

Fixes #258
This commit is contained in:
Miek Gieben
2016-10-10 12:09:29 +01:00
committed by GitHub
parent caa3976bfe
commit c22b7b2252
13 changed files with 348 additions and 108 deletions

View File

@@ -7,6 +7,7 @@ import (
"github.com/miekg/coredns/core/dnsserver"
"github.com/miekg/coredns/middleware"
"github.com/miekg/coredns/middleware/pkg/response"
"github.com/hashicorp/go-syslog"
"github.com/mholt/caddy"
@@ -105,6 +106,26 @@ func logParse(c *caddy.Controller) ([]Rule, error) {
Format: format,
})
}
// Class refinements in an extra block.
for c.NextBlock() {
switch c.Val() {
// class followed by all, denial, error or success.
case "class":
classes := c.RemainingArgs()
if len(classes) == 0 {
return nil, c.ArgErr()
}
cls, err := response.ClassFromString(classes[0])
if err != nil {
return nil, err
}
// update class and the last added Rule (bit icky)
rules[len(rules)-1].Class = cls
default:
return nil, c.ArgErr()
}
}
}
return rules, nil