log

package
v0.11.1 Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2024 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

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 SetLogger

func SetLogger(logger Logger)

SetLogger sets up a logger.

Types

type LogLevel

type LogLevel zapcore.Level

func ToLogLevel

func ToLogLevel(level string) LogLevel

ToLogLevel converts a string to a log level.

func (*LogLevel) String

func (l *LogLevel) String() string

type LogMode

type LogMode int8

LogMode defines the log output mode.

const (
	// LogModeProd is the log mode for production.
	LogModeProd LogMode = iota
	// LogModeDev is for more human-readable outputs, extra stack traces
	// and logging info. (aka Zap's "development config".)
	LogModeDev
)

func ToLogMode

func ToLogMode(mode string) LogMode

ToLogMode converts a string to a log mode. Use either 'production' for `LogModeProd` or 'development' for `LogModeDev`.

func (*LogMode) String

func (f *LogMode) String() string

type Logger

type Logger = logr.Logger
var (
	// Log is a singleton base logger that can be used across the system,
	// either directly or to create other loggers with name, with values,
	// and/or locked to a given log level.
	// It is initialized to the promise delegation log provided by
	// sigs.k8s.io/controller-runtime, which points to a no-op (null) logger
	// until `SetLogger` is called.
	// This is also useful for mocking the default logger tests.
	Log Logger = ctrl.Log
)

func FromContext

func FromContext(ctx context.Context, keysAndValues ...interface{}) Logger

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

func NewLogger

func NewLogger(opts Options) Logger

NewLogger returns a new logger with the given options. `logger` param is the actual logger implementation; when omitted, a new logger based on sigs.k8s.io/controller-runtime/pkg/log/zap is created.

func V

func V(level int) Logger

V uses the singleton logger to create a new logger for the given log level.

func WithName

func WithName(name string) Logger

WithName uses the singleton logger to create a new logger with the given name.

func WithValues

func WithValues(keysAndValues ...interface{}) Logger

WithName uses the singleton logger to create a new logger with the given values.

type Options

type Options struct {
	Level LogLevel
	Mode  LogMode
}

Options is a set of options for a configured logger.

Jump to

Keyboard shortcuts

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