middleware/log: make {size} the length of the request (#449)
* middleware/log: make {size} the length of the request {size} is the lenght of the request, {rsize} is the length of the reply. * Fix test
This commit is contained in:
parent
b85c6788dd
commit
b086e5f64d
4 changed files with 10 additions and 8 deletions
|
@ -62,19 +62,20 @@ The following place holders are supported:
|
||||||
* `{proto}`: protocol used (tcp or udp).
|
* `{proto}`: protocol used (tcp or udp).
|
||||||
* `{when}`: time of the query.
|
* `{when}`: time of the query.
|
||||||
* `{remote}`: client's IP address.
|
* `{remote}`: client's IP address.
|
||||||
|
* `{size}`: request size in bytes.
|
||||||
* `{port}`: client's port.
|
* `{port}`: client's port.
|
||||||
* `{rcode}`: response RCODE.
|
|
||||||
* `{size}`: response size.
|
|
||||||
* `{duration}`: response duration.
|
* `{duration}`: response duration.
|
||||||
* `{>bufsize}`: the EDNS0 buffer size advertized by the client.
|
* `{>bufsize}`: the EDNS0 buffer size advertised.
|
||||||
* `{>do}`: is the EDNS0 DO (DNSSEC OK) bit set.
|
* `{>do}`: is the EDNS0 DO (DNSSEC OK) bit set.
|
||||||
* `{>id}`: query ID
|
* `{>id}`: query ID
|
||||||
* `{>opcode}`: query OPCODE
|
* `{>opcode}`: query OPCODE.
|
||||||
|
* `{rcode}`: response RCODE.
|
||||||
|
* `{rsize}`: response size.
|
||||||
|
|
||||||
The default Common Log Format is:
|
The default Common Log Format is:
|
||||||
|
|
||||||
~~~ txt
|
~~~ txt
|
||||||
`{remote} - [{when}] "{type} {class} {name} {proto} {>do} {>bufsize}" {rcode} {size} {duration}`
|
`{remote} - [{when}] "{type} {class} {name} {proto} {size} {>do} {>bufsize}" {rcode} {rsize} {duration}`
|
||||||
~~~
|
~~~
|
||||||
|
|
||||||
## Examples
|
## Examples
|
||||||
|
|
|
@ -80,7 +80,7 @@ const (
|
||||||
// DefaultLogFilename is the default log filename.
|
// DefaultLogFilename is the default log filename.
|
||||||
DefaultLogFilename = "query.log"
|
DefaultLogFilename = "query.log"
|
||||||
// CommonLogFormat is the common log format.
|
// CommonLogFormat is the common log format.
|
||||||
CommonLogFormat = `{remote} ` + CommonLogEmptyValue + ` [{when}] "{type} {class} {name} {proto} {>do} {>bufsize}" {rcode} {size} {duration}`
|
CommonLogFormat = `{remote} ` + CommonLogEmptyValue + ` [{when}] "{type} {class} {name} {proto} {size} {>do} {>bufsize}" {rcode} {rsize} {duration}`
|
||||||
// CommonLogEmptyValue is the common empty log value.
|
// CommonLogEmptyValue is the common empty log value.
|
||||||
CommonLogEmptyValue = "-"
|
CommonLogEmptyValue = "-"
|
||||||
// CombinedLogFormat is the combined log format.
|
// CombinedLogFormat is the combined log format.
|
||||||
|
|
|
@ -39,7 +39,7 @@ func TestLoggedStatus(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
logged := f.String()
|
logged := f.String()
|
||||||
if !strings.Contains(logged, "A IN example.org. udp false 512") {
|
if !strings.Contains(logged, "A IN example.org. udp 29 false 512") {
|
||||||
t.Errorf("Expected it to be logged. Logged string: %s", logged)
|
t.Errorf("Expected it to be logged. Logged string: %s", logged)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,6 +42,7 @@ func New(r *dns.Msg, rr *dnsrecorder.Recorder, emptyValue string) Replacer {
|
||||||
"{when}": func() string {
|
"{when}": func() string {
|
||||||
return time.Now().Format(timeFormat)
|
return time.Now().Format(timeFormat)
|
||||||
}(),
|
}(),
|
||||||
|
"{size}": strconv.Itoa(req.Len()),
|
||||||
"{remote}": req.IP(),
|
"{remote}": req.IP(),
|
||||||
"{port}": req.Port(),
|
"{port}": req.Port(),
|
||||||
},
|
},
|
||||||
|
@ -53,7 +54,7 @@ func New(r *dns.Msg, rr *dnsrecorder.Recorder, emptyValue string) Replacer {
|
||||||
rcode = strconv.Itoa(rr.Rcode)
|
rcode = strconv.Itoa(rr.Rcode)
|
||||||
}
|
}
|
||||||
rep.replacements["{rcode}"] = rcode
|
rep.replacements["{rcode}"] = rcode
|
||||||
rep.replacements["{size}"] = strconv.Itoa(rr.Len)
|
rep.replacements["{rsize}"] = strconv.Itoa(rr.Len)
|
||||||
rep.replacements["{duration}"] = time.Since(rr.Start).String()
|
rep.replacements["{duration}"] = time.Since(rr.Start).String()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue