format

package
v1.0.13 Latest Latest
Warning

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

Go to latest
Published: Sep 9, 2020 License: MIT Imports: 8 Imported by: 20

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ContextField

type ContextField struct {
	Key string
	Val interface{}
}

ContextField is a name/value pair within the context fields.

type JSON

type JSON struct {
	// DisableTimestamp disables output of timestamp field.
	DisableTimestamp bool
	// DisableLevel disables output of level field.
	DisableLevel bool
	// DisableMsg disables output of msg field.
	DisableMsg bool
	// DisableContext disables output of all context fields.
	DisableContext bool
	// DisableStacktrace disables output of stack trace.
	DisableStacktrace bool

	// TimestampFormat is an optional format for timestamps. If empty
	// then DefTimestampFormat is used.
	TimestampFormat string

	// Deprecated: this has no effect.
	Indent string

	// EscapeHTML determines if certain characters (e.g. `<`, `>`, `&`)
	// are escaped.
	EscapeHTML bool

	// KeyTimestamp overrides the timestamp field key name.
	KeyTimestamp string

	// KeyLevel overrides the level field key name.
	KeyLevel string

	// KeyMsg overrides the msg field key name.
	KeyMsg string

	// KeyContextFields when not empty will group all context fields
	// under this key.
	KeyContextFields string

	// KeyStacktrace overrides the stacktrace field key name.
	KeyStacktrace string

	// ContextSorter allows custom sorting for the context fields.
	ContextSorter func(fields logr.Fields) []ContextField
	// contains filtered or unexported fields
}

JSON formats log records as JSON.

func (*JSON) Format

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

Format converts a log record to bytes in JSON format.

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 (rec JSONLogRec) MarshalJSONObject(enc *gojay.Encoder)

MarshalJSONObject encodes the LogRec as JSON.

type Plain

type Plain struct {
	// DisableTimestamp disables output of timestamp field.
	DisableTimestamp bool
	// DisableLevel disables output of level field.
	DisableLevel bool
	// DisableMsg disables output of msg field.
	DisableMsg bool
	// DisableContext disables output of all context fields.
	DisableContext bool
	// DisableStacktrace disables output of stack trace.
	DisableStacktrace bool

	// Delim is an optional delimiter output between each log field.
	// Defaults to a single space.
	Delim string

	// TimestampFormat is an optional format for timestamps. If empty
	// then DefTimestampFormat is used.
	TimestampFormat string
}

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

func (*Plain) Format

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

Format converts a log record to bytes.

Jump to

Keyboard shortcuts

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