plugin/log: allow various combinations of classes of responses (#1664)

This allows to log responses of different classes, for example, denial and error.
This commit is contained in:
Maksim Paramonau
2018-04-11 09:50:16 +03:00
committed by Miek Gieben
parent a20b4fe2de
commit ccfe691b95
4 changed files with 61 additions and 15 deletions

View File

@@ -52,11 +52,13 @@ func logParse(c *caddy.Controller) ([]Rule, error) {
rules = append(rules, Rule{
NameScope: ".",
Format: DefaultLogFormat,
Class: make(map[response.Class]bool),
})
} else if len(args) == 1 {
rules = append(rules, Rule{
NameScope: dns.Fqdn(args[0]),
Format: DefaultLogFormat,
Class: make(map[response.Class]bool),
})
} else {
// Name scope, and maybe a format specified
@@ -74,28 +76,33 @@ func logParse(c *caddy.Controller) ([]Rule, error) {
rules = append(rules, Rule{
NameScope: dns.Fqdn(args[0]),
Format: format,
Class: make(map[response.Class]bool),
})
}
// Class refinements in an extra block.
for c.NextBlock() {
switch c.Val() {
// class followed by all, denial, error or success.
// class followed by combinations of all, denial, error and 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
for _, c := range classes {
cls, err := response.ClassFromString(c)
if err != nil {
return nil, err
}
rules[len(rules)-1].Class[cls] = true
}
// update class and the last added Rule (bit icky)
rules[len(rules)-1].Class = cls
default:
return nil, c.ArgErr()
}
}
if len(rules[len(rules)-1].Class) == 0 {
rules[len(rules)-1].Class[response.All] = true
}
}
return rules, nil