sink

package
v2.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 10, 2022 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TimeStampKey = "_ts"
	FileLineKey  = "_file:line"
	LevelKey     = "_level"
	ComponentKey = "_component"
	MessageKey   = "_message"
	ErrorKey     = "_error"
)

Keys used to log specific builtin fields

Variables

View Source
var TimestampFunc = func() string {
	return time.Now().UTC().Format(time.RFC3339Nano)
}

TimestampFunc returns a string formatted version of the current time. This should probably only be used with tests or if you want to change the default time formatting of the output logs.

Functions

This section is empty.

Types

type Encoder

type Encoder interface {
	Encode(w io.Writer, entry interface{}) error
}

Encoder encodes messages

type JSONEncoder

type JSONEncoder struct{}

JSONEncoder encodes messages as JSON

func (JSONEncoder) Encode

func (j JSONEncoder) Encode(w io.Writer, entry interface{}) error

Encode encodes the message as JSON to w

type Line

type Line struct {
	Timestamp string
	FileLine  string
	Verbosity string
	Component string
	Message   string
	Context   map[string]interface{}
}

Line orders log line fields

func (Line) MarshalJSON

func (l Line) MarshalJSON() ([]byte, error)

MarshalJSON implements custom marshaling for log line: (1) flattening context (2) support for developer mode

type LineJSON

type LineJSON struct {
	Timestamp string                 `json:"_ts"`
	FileLine  string                 `json:"-"`
	Verbosity string                 `json:"_level"`
	Component string                 `json:"_component"`
	Message   string                 `json:"_message"`
	Context   map[string]interface{} `json:"-"`
}

LineJSON add json tags to Line struct (production logs)

type LineJSONDev

type LineJSONDev struct {
	Timestamp string                 `json:"_ts"`
	FileLine  string                 `json:"_file:line"`
	Verbosity string                 `json:"_level"`
	Component string                 `json:"_component"`
	Message   string                 `json:"_message"`
	Context   map[string]interface{} `json:"-"`
}

LineJSONDev add json tags to Line struct (developer logs, enable using environment variable LOG_DEV)

type Sink

type Sink struct {
	// contains filtered or unexported fields
}

Sink writes logs to a specified output

func NewLogSink

func NewLogSink(name string, w io.Writer, v Verbosity, e Encoder, keysAndValues ...interface{}) *Sink

NewLogSink creates a new logsink

func (*Sink) Enabled

func (s *Sink) Enabled(level int) bool

Enabled determines if a logger should record a log. If the log's verbosity is higher or equal to that the logger's level, the log is recorded. Otherwise, it is skipped.

func (*Sink) Error

func (s *Sink) Error(err error, msg string, keysAndValues ...interface{})

Error logs an error, with the given message and key/value pairs as context. Unlike Info, it bypasses the Enabled check. Logs will always be recorded from this method.

func (*Sink) GetVerbosity

func (s *Sink) GetVerbosity() int

GetVerbosity returns the log level

func (*Sink) Info

func (s *Sink) Info(level int, msg string, keysAndValues ...interface{})

Info logs a non-error message with the given key/value pairs as context. Info will check to see if the log is enabled for the logger's level before recording.

func (*Sink) Init

func (s *Sink) Init(info logr.RuntimeInfo)

Init receives optional information about the logr library for LogSink implementations that need it.

func (*Sink) SetOutput

func (s *Sink) SetOutput(w io.Writer)

SetOutput sets the writer that JSON is written to

func (*Sink) SetVerbosity

func (s *Sink) SetVerbosity(v int)

SetVerbosity sets the log level allowed by the logsink

func (*Sink) WithName

func (s *Sink) WithName(name string) logr.LogSink

WithName clones the logsink and overwrites the name.

func (*Sink) WithValues

func (s *Sink) WithValues(keysAndValues ...interface{}) logr.LogSink

WithValues clones the logsink and appends keysAndValues.

type Verbosity

type Verbosity int

Verbosity is a level of verbosity to log between 0 and math.MaxInt32 However it is recommended to keep the numbers between 0 and 3

func (Verbosity) MarshalJSON

func (v Verbosity) MarshalJSON() ([]byte, error)

MarshalJSON marshas JSON

func (Verbosity) String

func (v Verbosity) String() string

Jump to

Keyboard shortcuts

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