log

package
v0.0.0-...-728477c Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2024 License: Apache-2.0, BSD-2-Clause, BSD-3-Clause, + 3 more Imports: 10 Imported by: 1

Documentation

Overview

Package log contains the global logger for the vineyard operator.

Index

Constants

This section is empty.

Variables

View Source
var (
	Log = Logger{newLogrLogger(dlog).WithName("vineyard")}
)

Functions

func Error

func Error(err error, msg string, keysAndValues ...any)

func Errorf

func Errorf(err error, format string, v ...any)

func Fatal

func Fatal(err error, msg string, keysAndValues ...any)

func Fatalf

func Fatalf(err error, format string, v ...any)

func Info

func Info(msg string, keysAndValues ...any)

func Infof

func Infof(format string, v ...any)

func IntoContext

func IntoContext(ctx context.Context, log Logger) context.Context

IntoContext takes a context and sets the logger as one of its values. Use FromContext function to retrieve the logger.

func Output

func Output(msg string)

func Outputf

func Outputf(msg string, keysAndValues ...any)

func SetLogLevel

func SetLogLevel(level int)

func SetLogger

func SetLogger(l Logger)

SetLogger sets a concrete logging implementation for all deferred Loggers.

Types

type CallDepthLogSink

type CallDepthLogSink interface {
	// WithCallDepth returns a LogSink that will offset the call
	// stack by the specified number of frames when logging call
	// site information.
	//
	// If depth is 0, the LogSink should skip exactly the number
	// of call frames defined in RuntimeInfo.CallDepth when Info
	// or Error are called, i.e. the attribution should be to the
	// direct caller of Logger.Info or Logger.Error.
	//
	// If depth is 1 the attribution should skip 1 call frame, and so on.
	// Successive calls to this are additive.
	WithCallDepth(depth int) logr.Logger
}

CallDepthLogSink represents a Logger that knows how to climb the call stack to identify the original call site and can offset the depth by a specified number of frames. This is useful for users who have helper functions between the "real" call site and the actual calls to Logger methods. Implementations that log information about the call site (such as file, function, or line) would otherwise log information about the intermediate helper functions.

This is an optional interface and implementations are not required to support it.

type DelegatingLogSink

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

DelegatingLogSink is a logsink that delegates to another logr.LogSink. If the underlying promise is not nil, it registers calls to sub-loggers with the logging factory to be populated later, and returns a new delegating logger. It expects to have *some* logr.Logger set at all times (generally a no-op logger before the promises are fulfilled).

func NewDelegatingLogSink

func NewDelegatingLogSink(initial logr.Logger) *DelegatingLogSink

NewDelegatingLogSink constructs a new DelegatingLogSink which uses the given logger before its promise is fulfilled.

func (*DelegatingLogSink) Enabled

func (l *DelegatingLogSink) Enabled() bool

Enabled tests whether this Logger is enabled. For example, commandline flags might be used to set the logging verbosity and disable some info logs.

func (*DelegatingLogSink) Error

func (l *DelegatingLogSink) Error(err error, msg string, keysAndValues ...any)

Error logs an error, with the given message and key/value pairs as context. It functions similarly to calling Info with the "error" named value, but may have unique behavior, and should be preferred for logging errors (see the package documentations for more information).

The msg field should be used to add context to any underlying error, while the err field should be used to attach the actual error that triggered this log line, if present.

func (*DelegatingLogSink) Fulfill

func (l *DelegatingLogSink) Fulfill(actual logr.Logger)

Fulfill switches the logger over to use the actual logger provided, instead of the temporary initial one, if this method has not been previously called.

func (*DelegatingLogSink) Info

func (l *DelegatingLogSink) Info(msg string, keysAndValues ...any)

Info logs a non-error message with the given key/value pairs as context.

The msg argument should be used to add some constant description to the log line. The key/value pairs can then be used to add additional variable information. The key/value pairs should alternate string keys and arbitrary values.

func (*DelegatingLogSink) Init

func (l *DelegatingLogSink) Init(info RuntimeInfo)

Init implements logr.LogSink.

func (*DelegatingLogSink) V

func (l *DelegatingLogSink) V(level int) logr.Logger

func (*DelegatingLogSink) WithName

func (l *DelegatingLogSink) WithName(name string) logr.Logger

WithName provides a new Logger with the name appended.

func (*DelegatingLogSink) WithValues

func (l *DelegatingLogSink) WithValues(tags ...any) logr.Logger

WithValues provides a new Logger with the tags appended.

type EscapeSeqJSONEncoder

type EscapeSeqJSONEncoder struct {
	zapcore.Encoder
}

func (*EscapeSeqJSONEncoder) Clone

func (enc *EscapeSeqJSONEncoder) Clone() zapcore.Encoder

func (*EscapeSeqJSONEncoder) EncodeEntry

func (enc *EscapeSeqJSONEncoder) EncodeEntry(entry zapcore.Entry, fields []zapcore.Field) (*buffer.Buffer, error)

type Logger

type Logger struct {
	logr.Logger
}

Extends the logr's logger with Fatal support

func FromContext

func FromContext(ctx context.Context, keysAndValues ...any) Logger

FromContext returns a logger with predefined values from a context.Context.

func V

func V(level int) Logger

func WithName

func WithName(name string) Logger

func WithValues

func WithValues(keysAndValues ...any) Logger

func (Logger) Errorf

func (l Logger) Errorf(err error, format string, v ...any)

func (Logger) Fatal

func (l Logger) Fatal(err error, msg string, keysAndValues ...any)

func (Logger) Fatalf

func (l Logger) Fatalf(err error, format string, v ...any)

func (Logger) Infof

func (l Logger) Infof(format string, v ...any)

func (Logger) Output

func (l Logger) Output(msg string)

func (Logger) Outputf

func (l Logger) Outputf(format string, v ...any)

type RuntimeInfo

type RuntimeInfo struct {
	// CallDepth is the number of call frames the logr library adds between the
	// end-user and the LogSink.  LogSink implementations which choose to print
	// the original logging site (e.g. file & line) should climb this many
	// additional frames to find it.
	CallDepth int
}

RuntimeInfo holds information that the logr "core" library knows which LogSinks might want to know.

Jump to

Keyboard shortcuts

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