2016-03-19 12:58:08 +00:00
# log
2016-03-19 11:16:08 +00:00
2018-01-04 12:53:07 +00:00
## Name
*log* - enables query logging to standard output.
## Description
By just using * log * you dump all queries (and parts for the reply) on standard output. Options exist
2020-01-17 16:16:29 +01:00
to tweak the output a little. Note that for busy servers logging will incur a performance hit.
2018-01-04 12:53:07 +00:00
2020-01-17 16:16:29 +01:00
Enabling or disabling the * log * plugin only affects the query logging, any other logging from
CoreDNS will show up regardless.
2016-03-19 11:16:08 +00:00
## Syntax
2016-10-10 12:09:29 +01:00
~~~ txt
2016-03-19 11:16:08 +00:00
log
~~~
2020-01-17 16:16:29 +01:00
With no arguments, a query log entry is written to * stdout * in the common log format for all requests.
2017-10-10 09:39:35 +02:00
Or if you want/need slightly more control:
2016-03-19 11:16:08 +00:00
2016-10-10 12:09:29 +01:00
~~~ txt
2019-01-08 15:40:50 +08:00
log [NAMES...] [FORMAT]
2016-03-19 11:16:08 +00:00
~~~
2019-01-08 15:40:50 +08:00
* `NAMES` is the name list to match in order to be logged
2019-01-04 19:39:02 +00:00
* `FORMAT` is the log format to use (default is Common Log Format), `{common}` is used as a shortcut
for the Common Log Format. You can also use `{combined}` for a format that adds the query opcode
`{>opcode}` to the Common Log Format.
2016-03-19 11:16:08 +00:00
2018-04-11 21:07:10 +03:00
You can further specify the classes of responses that get logged:
2016-10-10 12:09:29 +01:00
~~~ txt
2019-01-08 15:40:50 +08:00
log [NAMES...] [FORMAT] {
2018-04-11 21:07:10 +03:00
class CLASSES...
2016-10-10 12:09:29 +01:00
}
~~~
2018-04-11 21:07:10 +03:00
* `CLASSES` is a space-separated list of classes of responses that should be logged
The classes of responses have the following meaning:
2016-10-10 12:09:29 +01:00
* `success` : successful response
2019-01-05 16:33:27 +00:00
* `denial` : either NXDOMAIN or nodata responses (Name exists, type does not). A nodata response
sets the return code to NOERROR.
2016-11-09 13:02:06 +00:00
* `error` : SERVFAIL, NOTIMP, REFUSED, etc. Anything that indicates the remote server is not willing to
2020-01-17 16:16:29 +01:00
resolve the request.
2019-01-04 19:39:02 +00:00
* `all` : the default - nothing is specified. Using of this class means that all messages will be
logged whatever we mix together with "all".
2016-10-10 12:09:29 +01:00
2020-01-17 16:16:29 +01:00
If no class is specified, it defaults to `all` .
2016-10-10 12:09:29 +01:00
2016-03-19 11:16:08 +00:00
## Log Format
2016-04-03 17:05:16 +01:00
You can specify a custom log format with any placeholder values. Log supports both request and
response placeholders.
The following place holders are supported:
2017-08-07 03:49:40 -07:00
* `{type}` : qtype of the request
* `{name}` : qname of the request
* `{class}` : qclass of the request
* `{proto}` : protocol used (tcp or udp)
2018-02-28 18:15:12 -08:00
* `{remote}` : client's IP address, for IPv6 addresses these are enclosed in brackets: `[::1]`
2018-11-13 14:20:49 -05:00
* `{local}` : server's IP address, for IPv6 addresses these are enclosed in brackets: `[::1]`
2017-08-07 03:49:40 -07:00
* `{size}` : request size in bytes
* `{port}` : client's port
* `{duration}` : response duration
* `{rcode}` : response RCODE
2018-11-03 18:58:15 +00:00
* `{rsize}` : raw (uncompressed), response size (a client may receive a smaller response)
2017-08-07 03:49:40 -07:00
* `{>rflags}` : response flags, each set flag will be displayed, e.g. "aa, tc". This includes the qr
2018-11-03 18:58:15 +00:00
bit as well
2017-08-07 03:49:40 -07:00
* `{>bufsize}` : the EDNS0 buffer size advertised in the query
* `{>do}` : is the EDNS0 DO (DNSSEC OK) bit set in the query
2016-04-03 17:05:16 +01:00
* `{>id}` : query ID
2017-08-07 03:49:40 -07:00
* `{>opcode}` : query OPCODE
2019-01-04 19:39:02 +00:00
* `{common}` : the default Common Log Format.
* `{combined}` : the Common Log Format with the query opcode.
2019-01-05 16:33:27 +00:00
* `{/LABEL}` : any metadata label is accepted as a place holder if it is enclosed between `{/` and
`}` , the place holder will be replaced by the corresponding metadata value or the default value
`-` if label is not defined. See the * metadata * plugin for more information.
2016-04-03 17:05:16 +01:00
2016-10-10 12:09:29 +01:00
The default Common Log Format is:
~~~ txt
2018-10-31 21:32:23 +00:00
`{remote}:{port} - {>id} "{type} {class} {name} {proto} {size} {>do} {>bufsize}" {rcode} {>rflags} {rsize} {duration}`
2016-10-10 12:09:29 +01:00
~~~
2016-03-19 11:16:08 +00:00
2018-10-31 21:32:23 +00:00
Each of these logs will be outputted with `log.Infof` , so a typical example looks like this:
~~~ txt
2019-09-19 14:17:53 +01:00
[INFO] [::1]:50759 - 29008 "A IN example.org. udp 41 false 4096" NOERROR qr,rd,ra,ad 68 0.037990251s
2021-06-08 16:33:15 +02:00
~~~
2018-10-31 21:32:23 +00:00
2026-01-26 08:03:03 -08:00
## Additional metadata
The log plugin adds the following metadata to allow for granular differentiation of NOERROR denial vs success messages. These are mapped from `plugin/pkg/response/classify.go` and `plugin/pkg/response/typify.go` .
* `{/log/class}` : success, denial
* `{/log/type}` : NODATA, NXDOMAIN, NOERROR
~~~ corefile
. {
log . "{proto} Request: {name} {type} {/log/class} {/log/type}"
}
~~~
2016-03-19 11:16:08 +00:00
## Examples
2017-05-31 20:28:53 +01:00
Log all requests to stdout
2016-03-19 11:16:08 +00:00
2017-10-10 09:39:35 +02:00
~~~ corefile
. {
log
whoami
}
2016-03-19 11:16:08 +00:00
~~~
2017-05-31 20:28:53 +01:00
Custom log format, for all zones (`.` )
2016-03-19 11:16:08 +00:00
2017-10-10 09:39:35 +02:00
~~~ corefile
. {
2017-11-13 10:23:27 +01:00
log . "{proto} Request: {name} {type} {>id}"
2017-10-10 09:39:35 +02:00
}
2016-03-19 11:16:08 +00:00
~~~
2016-10-10 12:09:29 +01:00
2019-01-05 16:33:27 +00:00
Only log denials (NXDOMAIN and nodata) for example.org (and below)
2016-10-10 12:09:29 +01:00
2017-10-10 09:39:35 +02:00
~~~ corefile
. {
2017-11-13 10:23:27 +01:00
log example.org {
2017-10-10 09:39:35 +02:00
class denial
}
2016-10-10 12:09:29 +01:00
}
~~~
2018-04-11 21:07:10 +03:00
2019-01-04 19:39:02 +00:00
Log all queries which were not resolved successfully in the Combined Log Format.
2018-04-11 21:07:10 +03:00
~~~ corefile
. {
2019-01-04 19:39:02 +00:00
log . {combined} {
2018-04-11 21:07:10 +03:00
class denial error
}
}
~~~
Log all queries on which we did not get errors
~~~ corefile
. {
log . {
class denial success
}
}
~~~
Also the multiple statements can be OR-ed, for example, we can rewrite the above case as following:
~~~ corefile
. {
log . {
class denial
class success
}
}
~~~