...

Package logger

import "github.com/go-kivik/kivik/v4/x/kivikd/logger"
Overview
Index

Overview ▾

Package logger defines the logger used by kivikd.

Constants

Pre-defined log fields

const (
    FieldUsername     = "username"
    FieldTimestamp    = "timestamp"
    FieldElapsedTime  = "elapsed"
    FieldResponseSize = "size"
)

Variables

DefaultLogger logs to stderr.

var DefaultLogger = New(os.Stderr)

type Fields

Fields is simple wrapper around logging fields.

type Fields map[string]interface{}

func (Fields) Exists

func (f Fields) Exists(key string) bool

Exists returns true if the requested key exists in the map.

func (Fields) Get

func (f Fields) Get(key string) interface{}

Get returns the value associated with a key.

func (Fields) GetDuration

func (f Fields) GetDuration(key string) time.Duration

GetDuration returns a value as a time.Duration

func (Fields) GetInt

func (f Fields) GetInt(key string) int

GetInt returns a value as an int.

func (Fields) GetString

func (f Fields) GetString(key string) string

GetString returns a value as a string, or "-"

func (Fields) GetTime

func (f Fields) GetTime(key string) time.Time

GetTime returns a value as a timestamp.

type RequestLogger

RequestLogger is a request logger.

type RequestLogger interface {
    Log(req *http.Request, status int, fields Fields)
}

func New

func New(w io.Writer) RequestLogger

New returns a new RequestLogger that writes apache-style logs to an io.Writer.