Document log replacements

Rename latency to duration.
This commit is contained in:
Miek Gieben 2016-04-03 17:05:16 +01:00
parent 8d0d324f27
commit dd537b163d
2 changed files with 24 additions and 2 deletions

View file

@ -33,7 +33,26 @@ CoreDNS will create it before appending to it.
## Log Format ## Log Format
You can specify a custom log format with any placeholder values. Log supports both request and response placeholders. You can specify a custom log format with any placeholder values. Log supports both request and
response placeholders.
The following place holders are supported:
* `{type}`: qtype of the request.
* `{name}`: qname of the request.
* `{class}`: class of the request.
* `{proto}`: protocol used (tcp or udp).
* `{when}`: time of the query.
* `{remote}`: client's IP address.
* `{port}`: client's port.
* `{rcode}`: response RCODE.
* `{size}`: response size.
* `{duration}`: response duration (in seconds).
* `{>bufsize}`: the EDNS0 buffer size advertized by the client.
* `{>do}`: is the EDNS0 DO (DNSSEC OK) bit set.
* `{>id}`: query ID
* `{>opcode}`: query OPCODE
## Log Rotation ## Log Rotation

View file

@ -1,6 +1,7 @@
package middleware package middleware
import ( import (
"fmt"
"strconv" "strconv"
"strings" "strings"
"time" "time"
@ -54,13 +55,15 @@ func NewReplacer(r *dns.Msg, rr *ResponseRecorder, emptyValue string) Replacer {
} }
rep.replacements["{rcode}"] = rcode rep.replacements["{rcode}"] = rcode
rep.replacements["{size}"] = strconv.Itoa(rr.size) rep.replacements["{size}"] = strconv.Itoa(rr.size)
rep.replacements["{latency}"] = time.Since(rr.start).String() rep.replacements["{duration}"] = time.Since(rr.start).String()
} }
// Header placeholders (case-insensitive) // Header placeholders (case-insensitive)
// TODO(miek): syntax for flags and document it // TODO(miek): syntax for flags and document it
rep.replacements[headerReplacer+"id}"] = strconv.Itoa(int(r.Id)) rep.replacements[headerReplacer+"id}"] = strconv.Itoa(int(r.Id))
rep.replacements[headerReplacer+"opcode}"] = strconv.Itoa(int(r.Opcode)) rep.replacements[headerReplacer+"opcode}"] = strconv.Itoa(int(r.Opcode))
rep.replacements[headerReplacer+"do}"] = fmt.Sprintf("%b", state.Do())
rep.replacements[headerReplacer+"bufsize}"] = strconv.Itoa(state.Size())
return rep return rep
} }