formatters

package
v2.0.21 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2023 License: MIT Imports: 10 Imported by: 2

Documentation

Index

Constants

View Source
const (
	GelfVersion      = "1.1"
	GelfVersionKey   = "version"
	GelfHostKey      = "host"
	GelfShortKey     = "short_message"
	GelfFullKey      = "full_message"
	GelfTimestampKey = "timestamp"
	GelfLevelKey     = "level"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type FieldArray

type FieldArray []logr.Field

func (FieldArray) IsNil

func (fa FieldArray) IsNil() bool

IsNil returns true if map is nil.

func (FieldArray) MarshalJSONObject

func (fa FieldArray) MarshalJSONObject(enc *gojay.Encoder)

MarshalJSONObject encodes Fields map to JSON.

type Gelf

type Gelf struct {
	// Hostname allows a custom hostname, otherwise os.Hostname is used
	Hostname string `json:"hostname"`

	// EnableCaller enables output of the file and line number that emitted a log record.
	EnableCaller bool `json:"enable_caller"`

	// FieldSorter allows custom sorting for the context fields.
	FieldSorter func(fields []logr.Field) []logr.Field `json:"-"`
}

Gelf formats log records as GELF rcords (https://docs.graylog.org/en/4.0/pages/gelf.html).

func (*Gelf) CheckValid

func (g *Gelf) CheckValid() error

func (*Gelf) Format

func (g *Gelf) Format(rec *logr.LogRec, level logr.Level, buf *bytes.Buffer) (*bytes.Buffer, error)

Format converts a log record to bytes in GELF format.

func (*Gelf) IsStacktraceNeeded added in v2.0.3

func (g *Gelf) IsStacktraceNeeded() bool

IsStacktraceNeeded returns true if a stacktrace is needed so we can output the `Caller` field.

type JSON

type JSON struct {
	// DisableTimestamp disables output of timestamp field.
	DisableTimestamp bool `json:"disable_timestamp"`
	// DisableLevel disables output of level field.
	DisableLevel bool `json:"disable_level"`
	// DisableMsg disables output of msg field.
	DisableMsg bool `json:"disable_msg"`
	// DisableFields disables output of all fields.
	DisableFields bool `json:"disable_fields"`
	// DisableStacktrace disables output of stack trace.
	DisableStacktrace bool `json:"disable_stacktrace"`
	// EnableCaller enables output of the file and line number that emitted a log record.
	EnableCaller bool `json:"enable_caller"`

	// TimestampFormat is an optional format for timestamps. If empty
	// then DefTimestampFormat is used.
	TimestampFormat string `json:"timestamp_format"`

	// KeyTimestamp overrides the timestamp field key name.
	KeyTimestamp string `json:"key_timestamp"`

	// KeyLevel overrides the level field key name.
	KeyLevel string `json:"key_level"`

	// KeyMsg overrides the msg field key name.
	KeyMsg string `json:"key_msg"`

	// KeyGroupFields when not empty will group all context fields
	// under this key.
	KeyGroupFields string `json:"key_group_fields"`

	// KeyStacktrace overrides the stacktrace field key name.
	KeyStacktrace string `json:"key_stacktrace"`

	// KeyCaller overrides the caller field key name.
	KeyCaller string `json:"key_caller"`

	// FieldSorter allows custom sorting of the fields. If nil then
	// no sorting is done.
	FieldSorter func(fields []logr.Field) []logr.Field `json:"-"`
	// contains filtered or unexported fields
}

JSON formats log records as JSON.

func (*JSON) CheckValid

func (j *JSON) CheckValid() error

func (*JSON) Format

func (j *JSON) Format(rec *logr.LogRec, level logr.Level, buf *bytes.Buffer) (*bytes.Buffer, error)

Format converts a log record to bytes in JSON format.

func (*JSON) IsStacktraceNeeded added in v2.0.3

func (j *JSON) IsStacktraceNeeded() bool

IsStacktraceNeeded returns true if a stacktrace is needed so we can output the `Caller` field.

type JSONLogRec

type JSONLogRec struct {
	*logr.LogRec
	*JSON
	// contains filtered or unexported fields
}

JSONLogRec decorates a LogRec adding JSON encoding.

func (JSONLogRec) IsNil

func (rec JSONLogRec) IsNil() bool

IsNil returns true if the LogRec pointer is nil.

func (JSONLogRec) MarshalJSONObject

func (jlr JSONLogRec) MarshalJSONObject(enc *gojay.Encoder)

MarshalJSONObject encodes the LogRec as JSON.

type Plain

type Plain struct {
	// DisableTimestamp disables output of timestamp field.
	DisableTimestamp bool `json:"disable_timestamp"`
	// DisableLevel disables output of level field.
	DisableLevel bool `json:"disable_level"`
	// DisableMsg disables output of msg field.
	DisableMsg bool `json:"disable_msg"`
	// DisableFields disables output of all fields.
	DisableFields bool `json:"disable_fields"`
	// DisableStacktrace disables output of stack trace.
	DisableStacktrace bool `json:"disable_stacktrace"`
	// EnableCaller enables output of the file and line number that emitted a log record.
	EnableCaller bool `json:"enable_caller"`

	// Delim is an optional delimiter output between each log field.
	// Defaults to a single space.
	Delim string `json:"delim"`

	// MinLevelLen sets the minimum level name length. If the level name is less
	// than the minimum it will be padded with spaces.
	MinLevelLen int `json:"min_level_len"`

	// MinMessageLen sets the minimum msg length. If the msg text is less
	// than the minimum it will be padded with spaces.
	MinMessageLen int `json:"min_msg_len"`

	// TimestampFormat is an optional format for timestamps. If empty
	// then DefTimestampFormat is used.
	TimestampFormat string `json:"timestamp_format"`

	// LineEnd sets the end of line character(s). Defaults to '\n'.
	LineEnd string `json:"line_end"`

	// EnableColor sets whether output should include color.
	EnableColor bool `json:"enable_color"`
}

Plain is the simplest formatter, outputting only text with no colors.

func (*Plain) CheckValid

func (p *Plain) CheckValid() error

func (*Plain) Format

func (p *Plain) Format(rec *logr.LogRec, level logr.Level, buf *bytes.Buffer) (*bytes.Buffer, error)

Format converts a log record to bytes.

func (*Plain) IsStacktraceNeeded added in v2.0.3

func (p *Plain) IsStacktraceNeeded() bool

IsStacktraceNeeded returns true if a stacktrace is needed so we can output the `Caller` field.

Jump to

Keyboard shortcuts

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