logging

package
v2.0.0-...-4d08927 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2020 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ConsoleEncoder

type ConsoleEncoder struct {
	zapcore.Encoder `json:"-"`
	LogEncoderConfig
}

ConsoleEncoder encodes log entries that are mostly human-readable.

func (ConsoleEncoder) CaddyModule

func (ConsoleEncoder) CaddyModule() caddy.ModuleInfo

CaddyModule returns the Caddy module information.

func (*ConsoleEncoder) Provision

func (ce *ConsoleEncoder) Provision(_ caddy.Context) error

Provision sets up the encoder.

func (*ConsoleEncoder) UnmarshalCaddyfile

func (ce *ConsoleEncoder) UnmarshalCaddyfile(d *caddyfile.Dispenser) error

UnmarshalCaddyfile sets up the module from Caddyfile tokens. Syntax:

console {
    <common encoder config subdirectives...>
}

See the godoc on the LogEncoderConfig type for the syntax of subdirectives that are common to most/all encoders.

type DeleteFilter

type DeleteFilter struct{}

DeleteFilter is a Caddy log field filter that deletes the field.

func (DeleteFilter) CaddyModule

func (DeleteFilter) CaddyModule() caddy.ModuleInfo

CaddyModule returns the Caddy module information.

func (DeleteFilter) Filter

func (DeleteFilter) Filter(in zapcore.Field) zapcore.Field

Filter filters the input field.

func (DeleteFilter) UnmarshalCaddyfile

func (DeleteFilter) UnmarshalCaddyfile(d *caddyfile.Dispenser) error

UnmarshalCaddyfile sets up the module from Caddyfile tokens.

type FileWriter

type FileWriter struct {
	// Filename is the name of the file to write.
	Filename string `json:"filename,omitempty"`

	// Roll toggles log rolling or rotation, which is
	// enabled by default.
	Roll *bool `json:"roll,omitempty"`

	// When a log file reaches approximately this size,
	// it will be rotated.
	RollSizeMB int `json:"roll_size_mb,omitempty"`

	// Whether to compress rolled files. Default: true
	RollCompress *bool `json:"roll_gzip,omitempty"`

	// Whether to use local timestamps in rolled filenames.
	// Default: false
	RollLocalTime bool `json:"roll_local_time,omitempty"`

	// The maximum number of rolled log files to keep.
	// Default: 10
	RollKeep int `json:"roll_keep,omitempty"`

	// How many days to keep rolled log files. Default: 90
	RollKeepDays int `json:"roll_keep_days,omitempty"`
}

FileWriter can write logs to files. By default, log files are rotated ("rolled") when they get large, and old log files get deleted, to ensure that the process does not exhaust disk space.

func (FileWriter) CaddyModule

func (FileWriter) CaddyModule() caddy.ModuleInfo

CaddyModule returns the Caddy module information.

func (FileWriter) OpenWriter

func (fw FileWriter) OpenWriter() (io.WriteCloser, error)

OpenWriter opens a new file writer.

func (*FileWriter) Provision

func (fw *FileWriter) Provision(ctx caddy.Context) error

Provision sets up the module

func (FileWriter) String

func (fw FileWriter) String() string

func (*FileWriter) UnmarshalCaddyfile

func (fw *FileWriter) UnmarshalCaddyfile(d *caddyfile.Dispenser) error

UnmarshalCaddyfile sets up the module from Caddyfile tokens. Syntax:

file <filename> {
    roll_disabled
    roll_size     <size>
    roll_keep     <num>
    roll_keep_for <days>
}

The roll_size value has megabyte resolution. Fractional values are rounded up to the next whole megabyte (MiB).

The roll_keep_for duration has day resolution. Fractional values are rounded up to the next whole number of days.

If any of the roll_size, roll_keep, or roll_keep_for subdirectives are omitted or set to a zero value, then Caddy's default value for that subdirective is used.

func (FileWriter) WriterKey

func (fw FileWriter) WriterKey() string

WriterKey returns a unique key representing this fw.

type FilterEncoder

type FilterEncoder struct {
	// The underlying encoder that actually
	// encodes the log entries. Required.
	WrappedRaw json.RawMessage `json:"wrap,omitempty" caddy:"namespace=caddy.logging.encoders inline_key=format"`

	// A map of field names to their filters. Note that this
	// is not a module map; the keys are field names.
	//
	// Nested fields can be referenced by representing a
	// layer of nesting with `>`. In other words, for an
	// object like `{"a":{"b":0}}`, the inner field can
	// be referenced as `a>b`.
	//
	// The following fields are fundamental to the log and
	// cannot be filtered because they are added by the
	// underlying logging library as special cases: ts,
	// level, logger, and msg.
	FieldsRaw map[string]json.RawMessage `json:"fields,omitempty" caddy:"namespace=caddy.logging.encoders.filter inline_key=filter"`

	Fields map[string]LogFieldFilter `json:"-"`
	// contains filtered or unexported fields
}

FilterEncoder can filter (manipulate) fields on log entries before they are actually encoded by an underlying encoder.

func (FilterEncoder) AddArray

func (fe FilterEncoder) AddArray(key string, marshaler zapcore.ArrayMarshaler) error

AddArray is part of the zapcore.ObjectEncoder interface. Array elements do not get filtered.

func (FilterEncoder) AddBinary

func (fe FilterEncoder) AddBinary(key string, value []byte)

AddBinary is part of the zapcore.ObjectEncoder interface.

func (FilterEncoder) AddBool

func (fe FilterEncoder) AddBool(key string, value bool)

AddBool is part of the zapcore.ObjectEncoder interface.

func (FilterEncoder) AddByteString

func (fe FilterEncoder) AddByteString(key string, value []byte)

AddByteString is part of the zapcore.ObjectEncoder interface.

func (FilterEncoder) AddComplex128

func (fe FilterEncoder) AddComplex128(key string, value complex128)

AddComplex128 is part of the zapcore.ObjectEncoder interface.

func (FilterEncoder) AddComplex64

func (fe FilterEncoder) AddComplex64(key string, value complex64)

AddComplex64 is part of the zapcore.ObjectEncoder interface.

func (FilterEncoder) AddDuration

func (fe FilterEncoder) AddDuration(key string, value time.Duration)

AddDuration is part of the zapcore.ObjectEncoder interface.

func (FilterEncoder) AddFloat32

func (fe FilterEncoder) AddFloat32(key string, value float32)

AddFloat32 is part of the zapcore.ObjectEncoder interface.

func (FilterEncoder) AddFloat64

func (fe FilterEncoder) AddFloat64(key string, value float64)

AddFloat64 is part of the zapcore.ObjectEncoder interface.

func (FilterEncoder) AddInt

func (fe FilterEncoder) AddInt(key string, value int)

AddInt is part of the zapcore.ObjectEncoder interface.

func (FilterEncoder) AddInt16

func (fe FilterEncoder) AddInt16(key string, value int16)

AddInt16 is part of the zapcore.ObjectEncoder interface.

func (FilterEncoder) AddInt32

func (fe FilterEncoder) AddInt32(key string, value int32)

AddInt32 is part of the zapcore.ObjectEncoder interface.

func (FilterEncoder) AddInt64

func (fe FilterEncoder) AddInt64(key string, value int64)

AddInt64 is part of the zapcore.ObjectEncoder interface.

func (FilterEncoder) AddInt8

func (fe FilterEncoder) AddInt8(key string, value int8)

AddInt8 is part of the zapcore.ObjectEncoder interface.

func (FilterEncoder) AddObject

func (fe FilterEncoder) AddObject(key string, marshaler zapcore.ObjectMarshaler) error

AddObject is part of the zapcore.ObjectEncoder interface.

func (FilterEncoder) AddReflected

func (fe FilterEncoder) AddReflected(key string, value interface{}) error

AddReflected is part of the zapcore.ObjectEncoder interface.

func (FilterEncoder) AddString

func (fe FilterEncoder) AddString(key, value string)

AddString is part of the zapcore.ObjectEncoder interface.

func (FilterEncoder) AddTime

func (fe FilterEncoder) AddTime(key string, value time.Time)

AddTime is part of the zapcore.ObjectEncoder interface.

func (FilterEncoder) AddUint

func (fe FilterEncoder) AddUint(key string, value uint)

AddUint is part of the zapcore.ObjectEncoder interface.

func (FilterEncoder) AddUint16

func (fe FilterEncoder) AddUint16(key string, value uint16)

AddUint16 is part of the zapcore.ObjectEncoder interface.

func (FilterEncoder) AddUint32

func (fe FilterEncoder) AddUint32(key string, value uint32)

AddUint32 is part of the zapcore.ObjectEncoder interface.

func (FilterEncoder) AddUint64

func (fe FilterEncoder) AddUint64(key string, value uint64)

AddUint64 is part of the zapcore.ObjectEncoder interface.

func (FilterEncoder) AddUint8

func (fe FilterEncoder) AddUint8(key string, value uint8)

AddUint8 is part of the zapcore.ObjectEncoder interface.

func (FilterEncoder) AddUintptr

func (fe FilterEncoder) AddUintptr(key string, value uintptr)

AddUintptr is part of the zapcore.ObjectEncoder interface.

func (FilterEncoder) CaddyModule

func (FilterEncoder) CaddyModule() caddy.ModuleInfo

CaddyModule returns the Caddy module information.

func (FilterEncoder) Clone

func (fe FilterEncoder) Clone() zapcore.Encoder

Clone is part of the zapcore.ObjectEncoder interface. We don't use it as of Oct 2019 (v2 beta 7), I'm not really sure what it'd be useful for in our case.

func (FilterEncoder) EncodeEntry

func (fe FilterEncoder) EncodeEntry(ent zapcore.Entry, fields []zapcore.Field) (*buffer.Buffer, error)

EncodeEntry partially implements the zapcore.Encoder interface.

func (FilterEncoder) OpenNamespace

func (fe FilterEncoder) OpenNamespace(key string)

OpenNamespace is part of the zapcore.ObjectEncoder interface.

func (*FilterEncoder) Provision

func (fe *FilterEncoder) Provision(ctx caddy.Context) error

Provision sets up the encoder.

func (*FilterEncoder) UnmarshalCaddyfile

func (fe *FilterEncoder) UnmarshalCaddyfile(d *caddyfile.Dispenser) error

UnmarshalCaddyfile sets up the module from Caddyfile tokens. Syntax:

filter {
    wrap <another encoder>
    fields {
        <field> <filter> {
            <filter options>
        }
    }
}

type IPMaskFilter

type IPMaskFilter struct {
	// The IPv4 mask, as an subnet size CIDR.
	IPv4MaskRaw int `json:"ipv4_cidr,omitempty"`

	// The IPv6 mask, as an subnet size CIDR.
	IPv6MaskRaw int `json:"ipv6_cidr,omitempty"`
	// contains filtered or unexported fields
}

IPMaskFilter is a Caddy log field filter that masks IP addresses.

func (IPMaskFilter) CaddyModule

func (IPMaskFilter) CaddyModule() caddy.ModuleInfo

CaddyModule returns the Caddy module information.

func (IPMaskFilter) Filter

func (m IPMaskFilter) Filter(in zapcore.Field) zapcore.Field

Filter filters the input field.

func (*IPMaskFilter) Provision

func (m *IPMaskFilter) Provision(ctx caddy.Context) error

Provision parses m's IP masks, from integers.

func (*IPMaskFilter) UnmarshalCaddyfile

func (m *IPMaskFilter) UnmarshalCaddyfile(d *caddyfile.Dispenser) error

UnmarshalCaddyfile sets up the module from Caddyfile tokens.

type JSONEncoder

type JSONEncoder struct {
	zapcore.Encoder `json:"-"`
	LogEncoderConfig
}

JSONEncoder encodes entries as JSON.

func (JSONEncoder) CaddyModule

func (JSONEncoder) CaddyModule() caddy.ModuleInfo

CaddyModule returns the Caddy module information.

func (*JSONEncoder) Provision

func (je *JSONEncoder) Provision(_ caddy.Context) error

Provision sets up the encoder.

func (*JSONEncoder) UnmarshalCaddyfile

func (je *JSONEncoder) UnmarshalCaddyfile(d *caddyfile.Dispenser) error

UnmarshalCaddyfile sets up the module from Caddyfile tokens. Syntax:

json {
    <common encoder config subdirectives...>
}

See the godoc on the LogEncoderConfig type for the syntax of subdirectives that are common to most/all encoders.

type LogEncoderConfig

type LogEncoderConfig struct {
	MessageKey     *string `json:"message_key,omitempty"`
	LevelKey       *string `json:"level_key,omitempty"`
	TimeKey        *string `json:"time_key,omitempty"`
	NameKey        *string `json:"name_key,omitempty"`
	CallerKey      *string `json:"caller_key,omitempty"`
	StacktraceKey  *string `json:"stacktrace_key,omitempty"`
	LineEnding     *string `json:"line_ending,omitempty"`
	TimeFormat     string  `json:"time_format,omitempty"`
	DurationFormat string  `json:"duration_format,omitempty"`
	LevelFormat    string  `json:"level_format,omitempty"`
}

LogEncoderConfig holds configuration common to most encoders.

func (*LogEncoderConfig) UnmarshalCaddyfile

func (lec *LogEncoderConfig) UnmarshalCaddyfile(d *caddyfile.Dispenser) error

UnmarshalCaddyfile populates the struct from Caddyfile tokens. Syntax:

{
    message_key <key>
    level_key   <key>
    time_key    <key>
    name_key    <key>
    caller_key  <key>
    stacktrace_key <key>
    line_ending  <char>
    time_format  <format>
    level_format <format>
}

func (*LogEncoderConfig) ZapcoreEncoderConfig

func (lec *LogEncoderConfig) ZapcoreEncoderConfig() zapcore.EncoderConfig

ZapcoreEncoderConfig returns the equivalent zapcore.EncoderConfig. If lec is nil, zap.NewProductionEncoderConfig() is returned.

type LogFieldFilter

type LogFieldFilter interface {
	Filter(zapcore.Field) zapcore.Field
}

LogFieldFilter can filter (or manipulate) a field in a log entry.

type LogfmtEncoder

type LogfmtEncoder struct {
	zapcore.Encoder `json:"-"`
	LogEncoderConfig
}

LogfmtEncoder encodes log entries as logfmt: https://www.brandur.org/logfmt

Note that logfmt does not encode nested structures properly, so it is not a good fit for most logs.

⚠️ DEPRECATED. Do not use. It will eventually be removed from the standard Caddy modules. For more information, see https://github.com/caddyserver/caddy/issues/3575.

func (LogfmtEncoder) CaddyModule

func (LogfmtEncoder) CaddyModule() caddy.ModuleInfo

CaddyModule returns the Caddy module information.

func (*LogfmtEncoder) Provision

func (lfe *LogfmtEncoder) Provision(ctx caddy.Context) error

Provision sets up the encoder.

func (*LogfmtEncoder) UnmarshalCaddyfile

func (lfe *LogfmtEncoder) UnmarshalCaddyfile(d *caddyfile.Dispenser) error

UnmarshalCaddyfile sets up the module from Caddyfile tokens. Syntax:

logfmt {
    <common encoder config subdirectives...>
}

See the godoc on the LogEncoderConfig type for the syntax of subdirectives that are common to most/all encoders.

type NetWriter

type NetWriter struct {
	Address string `json:"address,omitempty"`
	// contains filtered or unexported fields
}

NetWriter implements a log writer that outputs to a network socket.

func (NetWriter) CaddyModule

func (NetWriter) CaddyModule() caddy.ModuleInfo

CaddyModule returns the Caddy module information.

func (NetWriter) OpenWriter

func (nw NetWriter) OpenWriter() (io.WriteCloser, error)

OpenWriter opens a new network connection.

func (*NetWriter) Provision

func (nw *NetWriter) Provision(ctx caddy.Context) error

Provision sets up the module.

func (NetWriter) String

func (nw NetWriter) String() string

func (*NetWriter) UnmarshalCaddyfile

func (nw *NetWriter) UnmarshalCaddyfile(d *caddyfile.Dispenser) error

UnmarshalCaddyfile sets up the handler from Caddyfile tokens. Syntax:

net <address>

func (NetWriter) WriterKey

func (nw NetWriter) WriterKey() string

WriterKey returns a unique key representing this nw.

type SingleFieldEncoder

type SingleFieldEncoder struct {
	zapcore.Encoder `json:"-"`
	FieldName       string          `json:"field,omitempty"`
	FallbackRaw     json.RawMessage `json:"fallback,omitempty" caddy:"namespace=caddy.logging.encoders inline_key=format"`
}

SingleFieldEncoder writes a log entry that consists entirely of a single string field in the log entry. This is useful for custom, self-encoded log entries that consist of a single field in the structured log entry.

func (SingleFieldEncoder) CaddyModule

func (SingleFieldEncoder) CaddyModule() caddy.ModuleInfo

CaddyModule returns the Caddy module information.

func (SingleFieldEncoder) Clone

func (se SingleFieldEncoder) Clone() zapcore.Encoder

Clone wraps the underlying encoder's Clone. This is necessary because we implement our own EncodeEntry, and if we simply let the embedded encoder's Clone be promoted, it would return a clone of that, and we'd lose our SingleFieldEncoder's EncodeEntry.

func (SingleFieldEncoder) EncodeEntry

func (se SingleFieldEncoder) EncodeEntry(ent zapcore.Entry, fields []zapcore.Field) (*buffer.Buffer, error)

EncodeEntry partially implements the zapcore.Encoder interface.

func (*SingleFieldEncoder) Provision

func (se *SingleFieldEncoder) Provision(ctx caddy.Context) error

Provision sets up the encoder.

func (*SingleFieldEncoder) UnmarshalCaddyfile

func (se *SingleFieldEncoder) UnmarshalCaddyfile(d *caddyfile.Dispenser) error

UnmarshalCaddyfile sets up the module from Caddyfile tokens. Syntax:

single_field <field_name>

Jump to

Keyboard shortcuts

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