mirror of
https://github.com/coredns/coredns.git
synced 2025-10-28 00:34:24 -04:00
plugin/log: log remote port addr as well (#1573)
Log the remote's port, for IPv6 addr this means we should enclose the v6 address in brackets; make this the default for 'remote'.
This commit is contained in:
@@ -59,7 +59,7 @@ The following place holders are supported:
|
|||||||
* `{class}`: qclass of the request
|
* `{class}`: qclass of the request
|
||||||
* `{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, for IPv6 addresses these are enclosed in brackets: `[::1]`
|
||||||
* `{size}`: request size in bytes
|
* `{size}`: request size in bytes
|
||||||
* `{port}`: client's port
|
* `{port}`: client's port
|
||||||
* `{duration}`: response duration
|
* `{duration}`: response duration
|
||||||
@@ -75,7 +75,7 @@ The following place holders are supported:
|
|||||||
The default Common Log Format is:
|
The default Common Log Format is:
|
||||||
|
|
||||||
~~~ txt
|
~~~ txt
|
||||||
`{remote} - [{when}] {>id} "{type} {class} {name} {proto} {size} {>do} {>bufsize}" {rcode} {>rflags} {rsize} {duration}`
|
`{remote}:{port} - [{when}] {>id} "{type} {class} {name} {proto} {size} {>do} {>bufsize}" {rcode} {>rflags} {rsize} {duration}`
|
||||||
~~~
|
~~~
|
||||||
|
|
||||||
## Examples
|
## Examples
|
||||||
|
|||||||
@@ -78,7 +78,7 @@ type Rule struct {
|
|||||||
|
|
||||||
const (
|
const (
|
||||||
// CommonLogFormat is the common log format.
|
// CommonLogFormat is the common log format.
|
||||||
CommonLogFormat = `{remote} ` + CommonLogEmptyValue + ` [{when}] {>id} "{type} {class} {name} {proto} {size} {>do} {>bufsize}" {rcode} {>rflags} {rsize} {duration}`
|
CommonLogFormat = `{remote}:{port} ` + CommonLogEmptyValue + ` [{when}] {>id} "{type} {class} {name} {proto} {size} {>do} {>bufsize}" {rcode} {>rflags} {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.
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ func New(r *dns.Msg, rr *dnstest.Recorder, emptyValue string) Replacer {
|
|||||||
return time.Now().Format(timeFormat)
|
return time.Now().Format(timeFormat)
|
||||||
}(),
|
}(),
|
||||||
"{size}": strconv.Itoa(req.Len()),
|
"{size}": strconv.Itoa(req.Len()),
|
||||||
"{remote}": req.IP(),
|
"{remote}": addrToRFC3986(req.IP()),
|
||||||
"{port}": req.Port(),
|
"{port}": req.Port(),
|
||||||
},
|
},
|
||||||
emptyValue: emptyValue,
|
emptyValue: emptyValue,
|
||||||
@@ -155,6 +155,14 @@ func flagsToString(h dns.MsgHdr) string {
|
|||||||
return strings.Join(flags[:i], ",")
|
return strings.Join(flags[:i], ",")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// addrToRFC3986 will add brackets to the address if it is an IPv6 address.
|
||||||
|
func addrToRFC3986(addr string) string {
|
||||||
|
if strings.Contains(addr, ":") {
|
||||||
|
return "[" + addr + "]"
|
||||||
|
}
|
||||||
|
return addr
|
||||||
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
timeFormat = "02/Jan/2006:15:04:05 -0700"
|
timeFormat = "02/Jan/2006:15:04:05 -0700"
|
||||||
headerReplacer = "{>"
|
headerReplacer = "{>"
|
||||||
|
|||||||
Reference in New Issue
Block a user