logger

package
v0.46.0 Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2024 License: Apache-2.0 Imports: 6 Imported by: 43

Documentation

Overview

Package logger provides runtime configuration options for logging, making it easier to consistently have the same configuration options and flags across GitOps Toolkit components.

Index

Constants

View Source
const (
	TraceLevel = 2
	DebugLevel = 1
	InfoLevel  = 0
)

These are for convenience when doing log.V(...) to log at a particular level. They correspond to the logr equivalents of the zap levels above.

Variables

This section is empty.

Functions

func CapitalLevelEncoder added in v0.43.2

func CapitalLevelEncoder(l zapcore.Level, enc zapcore.PrimitiveArrayEncoder)

CapitalLevelEncoder is a zapcore.LevelEncoder that encodes the level to a capitalized string. It has the same behavior as zapcore.CapitalLevelEncoder, except that it encodes the trace level as "TRACE" instead of "LEVEL(-2)".

func LowercaseLevelEncoder added in v0.43.2

func LowercaseLevelEncoder(l zapcore.Level, enc zapcore.PrimitiveArrayEncoder)

LowercaseLevelEncoder is a zapcore.LevelEncoder that encodes the level to a lowercase string. It has the same behavior as zapcore.LowercaseLevelEncoder, except that it has a special case for the trace level, which it encodes as "trace" instead of "Level(-2)".

func NewLogger

func NewLogger(opts Options) logr.Logger

NewLogger returns a logger configured with the given Options, and timestamps set to the ISO8601 format.

func SetLogger added in v0.31.0

func SetLogger(logger logr.Logger)

SetLogger sets the logger for the controller-runtime and klog packages to the given logger. It is not thread-safe, and should be called as early as possible in the program's execution.

Types

type Options added in v0.6.0

type Options struct {
	LogEncoding string
	LogLevel    string
}

Options contains the configuration options for the runtime logger.

The struct can be used in the main.go file of your controller by binding it to the main flag set, and then utilizing the configured options later:

func main() {
	var (
		// other controller specific configuration variables
		loggerOptions logger.Options
	)

	// Bind the options to the main flag set, and parse it
	loggerOptions.BindFlags(flag.CommandLine)
	flag.Parse()

	// Use the values during the initialisation of the logger
	logger.SetLogger(logger.NewLogger(loggerOptions))
}

func (*Options) BindFlags added in v0.6.0

func (o *Options) BindFlags(fs *pflag.FlagSet)

BindFlags will parse the given pflag.FlagSet for logger option flags and set the Options accordingly.

Jump to

Keyboard shortcuts

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