Commit 7f36a853 authored by Miek Gieben's avatar Miek Gieben

Fix all the log replacers

parent dd537b16
......@@ -47,7 +47,7 @@ The following place holders are supported:
* `{port}`: client's port.
* `{rcode}`: response RCODE.
* `{size}`: response size.
* `{duration}`: response duration (in seconds).
* `{duration}`: response duration.
* `{>bufsize}`: the EDNS0 buffer size advertized by the client.
* `{>do}`: is the EDNS0 DO (DNSSEC OK) bit set.
* `{>id}`: query ID
......
......@@ -58,7 +58,7 @@ const (
// DefaultLogFilename is the default log filename.
DefaultLogFilename = "query.log"
// CommonLogFormat is the common log format.
CommonLogFormat = `{remote} ` + CommonLogEmptyValue + ` [{when}] "{type} {name} {proto}" {rcode} {size}`
CommonLogFormat = `{remote} ` + CommonLogEmptyValue + ` [{when}] "{type} {name} {proto} {>do} {>bufsize}" {rcode} {size} {duration}`
// CommonLogEmptyValue is the common empty log value.
CommonLogEmptyValue = "-"
// CombinedLogFormat is the combined log format.
......
package middleware
import (
"fmt"
"strconv"
"strings"
"time"
......@@ -62,7 +61,7 @@ func NewReplacer(r *dns.Msg, rr *ResponseRecorder, emptyValue string) Replacer {
// TODO(miek): syntax for flags and document it
rep.replacements[headerReplacer+"id}"] = strconv.Itoa(int(r.Id))
rep.replacements[headerReplacer+"opcode}"] = strconv.Itoa(int(r.Opcode))
rep.replacements[headerReplacer+"do}"] = fmt.Sprintf("%b", state.Do())
rep.replacements[headerReplacer+"do}"] = boolToString(state.Do())
rep.replacements[headerReplacer+"bufsize}"] = strconv.Itoa(state.Size())
return rep
......@@ -104,6 +103,13 @@ func (r replacer) Set(key, value string) {
r.replacements["{"+key+"}"] = value
}
func boolToString(b bool) string {
if b {
return "true"
}
return "false"
}
const (
timeFormat = "02/Jan/2006:15:04:05 -0700"
headerReplacer = "{>"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment