log

package
v1.29.0-alpha.64 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 23, 2023 License: MIT Imports: 17 Imported by: 0

README

log

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.

Syntax

log
  • With no arguments, a query log entry is written to stdout in the common log format for all requests

Or if you want/need slightly more control:

log [NAME] [FORMAT]
  • NAME is the name to match in order to be logged
  • FORMAT is the log format to use (default is Common Log Format)

You can further specify the class of responses that get logged:

log [NAME] [FORMAT] {
    class [success|denial|error|all]
}

Here success denial and error denotes the class of responses that should be logged. The classes have the following meaning:

  • success: successful response
  • denial: either NXDOMAIN or NODATA (name exists, type does not)
  • error: SERVFAIL, NOTIMP, REFUSED, etc. Anything that indicates the remote server is not willing to resolve the request.
  • all: the default - nothing is specified.

If no class is specified, it defaults to all.

Log Format

You can specify a custom log format with any placeholder values. Log supports both request and response placeholders.

The following place holders are supported:

  • {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
  • {remote}: client's IP address
  • {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
  • {>id}: query ID
  • {>opcode}: query OPCODE

The default Common Log Format is:

`{remote} - [{when}] {>id} "{type} {class} {name} {proto} {size} {>do} {>bufsize}" {rcode} {>rflags} {rsize} {duration}`

Examples

Log all requests to stdout

. {
    log
    whoami
}

Custom log format, for all zones (.)

. {
    log . "{proto} Request: {name} {type} {>id}"
}

Only log denials for example.org (and below to a file)

. {
    log example.org {
        class denial
        log_dir /var/logs/
    }
}

Documentation

Overview

Package log implements basic but useful request (access) logging plugin.

Index

Constants

View Source
const (
	// DefaultLogFilename is the default log filename.
	DefaultLogFilename = "/data/bcs/logs/bcs/"
	// CommonLogFormat is the common log format.
	CommonLogFormat = `{remote} ` + CommonLogEmptyValue +
		` [{when}] {>id} "{type} {class} {name} {proto} {size} {>do} {>bufsize}" {rcode} {>rflags} {rsize} {duration}`
	// CommonLogEmptyValue is the common empty log value.
	CommonLogEmptyValue = "-"
	// CombinedLogFormat is the combined log format.
	CombinedLogFormat = CommonLogFormat + ` "{>opcode}"`
	// DefaultLogFormat is the default log format.
	DefaultLogFormat = CommonLogFormat
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Logger

type Logger struct {
	Next      plugin.Handler
	Rules     []Rule
	ErrorFunc func(context.Context, dns.ResponseWriter, *dns.Msg, int) // failover error handler
}

Logger is a basic request logging plugin.

func (Logger) Name

func (l Logger) Name() string

Name implements the Handler interface.

func (Logger) ServeDNS

func (l Logger) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (int, error)

ServeDNS implements the plugin.Handler interface.

type Rule

type Rule struct {
	NameScope string
	Class     response.Class
	// OutputFile file or directory for logs
	OutputFile string
	Format     string
	Log        *log.Logger
}

Rule configures the logging plugin.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL