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
to tweak the output a little.
Note that for busy servers this will incur a performance hit.
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
~~~
2017-05-31 20:28:53 +01:00
* With no arguments, a query log entry is written to * stdout * in the common log format for all requests
2016-03-19 11:16:08 +00:00
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
2017-11-13 10:23:27 +01:00
log [NAME] [FORMAT]
2016-03-19 11:16:08 +00:00
~~~
2016-10-10 20:13:22 +01:00
* `NAME` is the name to match in order to be logged
* `FORMAT` is the log format to use (default is 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
2017-11-13 10:23:27 +01:00
log [NAME] [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
* `denial` : either NXDOMAIN or NODATA (name exists, type does not)
2016-11-09 13:02:06 +00:00
* `error` : SERVFAIL, NOTIMP, REFUSED, etc. Anything that indicates the remote server is not willing to
2016-10-10 12:09:29 +01:00
resolve the request.
2018-04-11 21:07:10 +03: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
2016-11-09 13:02:06 +00: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)
* `{when}` : time of the query
2018-02-28 18:15:12 -08:00
* `{remote}` : client'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
* `{rsize}` : response size
* `{>rflags}` : response flags, each set flag will be displayed, e.g. "aa, tc". This includes the qr
bit as well.
* `{>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
2018-10-29 21:50:31 +03:00
* `{local}` : server's IP address, for IPv6 addresses these are enclosed in brackets: `[::1]`
* `{A}` : number of the A type answers in the response
* `{AAAA}` : number of the AAAA type answers in the response
* `{forward/resolving_proxy}` : if the query was forwarded to a resolver, the IP address and port of that replied resolver, else empty. The metadata plugin needs to be enabled to use this placeholder
2016-04-03 17:05:16 +01:00
2016-10-10 12:09:29 +01:00
The default Common Log Format is:
~~~ txt
2018-02-28 18:15:12 -08:00
`{remote}:{port} - [{when}] {>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
## 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
Only log denials for example.org (and below to a file)
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
Log all queries which were not resolved successfully
~~~ corefile
. {
log . {
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
}
}
~~~