log

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2022 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Logger logr.Logger

Functions

func Encoder

func Encoder(encoder zapcore.Encoder) func(o *Options)

Encoder configures how the logger will encode the output e.g JSON or console. See Options.Encoder.

func Level

func Level(level zapcore.LevelEnabler) func(o *Options)

Level sets Options.Level, which configures the minimum enabled logging level e.g. Debug, Info. A zap log level should be multiplied by -1 to get the logr verbosity. For example, to get logr verbosity of 3, pass zapcore.Level(-3) to this Opts. See https://pkg.go.dev/github.com/go-logr/zapr for how zap level relates to logr verbosity.

func New

func New(opts ...Opts) logr.Logger

New returns a brand new Logger configured with Opts. It uses KcpAwareEncoder which adds Type information and Namespace/Name to the log.

func NewRaw

func NewRaw(opts ...Opts) *zap.Logger

NewRaw returns a new zap.Logger configured with the passed Opts or their defaults. It uses KcpAwareEncoder which adds Type information and Namespace/Name to the log.

Types

type EncoderConfigOption

type EncoderConfigOption func(*zapcore.EncoderConfig)

EncoderConfigOption is a function that can modify a `zapcore.EncoderConfig`.

type KcpAwareEncoder

type KcpAwareEncoder struct {
	// Encoder is the zapcore.Encoder that this encoder delegates to
	zapcore.Encoder

	// Verbose controls whether the full object is printed.
	// If false, only name, namespace, api version, and kind are printed.
	// Otherwise, the full object is logged.
	Verbose bool
}

KcpAwareEncoder is a KCP-aware Zap Encoder. Instead of trying to force Kubernetes objects to implement ObjectMarshaller, we just implement a wrapper around a normal ObjectMarshaller that checks for Kubernetes objects.

func (*KcpAwareEncoder) Clone

func (k *KcpAwareEncoder) Clone() zapcore.Encoder

Clone implements zapcore.Encoder.

func (*KcpAwareEncoder) EncodeEntry

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

EncodeEntry implements zapcore.Encoder.

type NewEncoderFunc

type NewEncoderFunc func(...EncoderConfigOption) zapcore.Encoder

NewEncoderFunc is a function that creates an Encoder using the provided EncoderConfigOptions.

type Options

type Options struct {
	// Encoder configures how Zap will encode the output.  Defaults to
	// console when Development is true and JSON otherwise
	Encoder zapcore.Encoder
	// EncoderConfigOptions can modify the EncoderConfig needed to initialize an Encoder.
	// See https://godoc.org/go.uber.org/zap/zapcore#EncoderConfig for the list of options
	// that can be configured.
	// Note that the EncoderConfigOptions are not applied when the Encoder option is already set.
	EncoderConfigOptions []EncoderConfigOption
	// NewEncoder configures Encoder using the provided EncoderConfigOptions.
	// Note that the NewEncoder function is not used when the Encoder option is already set.
	NewEncoder NewEncoderFunc
	// DestWriter controls the destination of the log output.  Defaults to
	// os.Stderr.
	DestWriter io.Writer
	// Level configures the verbosity of the logging.
	// Defaults to Debug when Development is true and Info otherwise.
	// A zap log level should be multiplied by -1 to get the logr verbosity.
	// For example, to get logr verbosity of 3, set this field to zapcore.Level(-3).
	// See https://pkg.go.dev/github.com/go-logr/zapr for how zap level relates to logr verbosity.
	Level zapcore.LevelEnabler
	// StacktraceLevel is the level at and above which stacktraces will
	// be recorded for all messages. Defaults to Warn when Development
	// is true and Error otherwise.
	// See Level for the relationship of zap log level to logr verbosity.
	StacktraceLevel zapcore.LevelEnabler
	// ZapOpts allows passing arbitrary zap.Options to configure on the
	// underlying Zap logger.
	ZapOpts []zap.Option
}

Options contains all possible settings.

func (*Options) BindFlags

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

BindFlags will parse the given flagset for zap option flags and set the log options accordingly zap-encoder: Zap log encoding (one of 'json' or 'console') zap-log-level: Zap Level to configure the verbosity of logging. Can be one of 'debug', 'info', 'error', or any integer value > 0 which corresponds to custom debug levels of increasing verbosity") zap-stacktrace-level: Zap Level at and above which stacktraces are captured (one of 'info', 'error' or 'panic')

type Opts

type Opts func(*Options)

Opts allows to manipulate Options.

func UseFlagOptions

func UseFlagOptions(in *Options) Opts

UseFlagOptions configures the logger to use the Options set by parsing zap option flags from the CLI. opts := zap.Options{} opts.BindFlags(flag.CommandLine) flag.Parse() log := zap.New(zap.UseFlagOptions(&opts))

func WriteTo

func WriteTo(out io.Writer) Opts

WriteTo configures the logger to write to the given io.Writer, instead of standard error. See Options.DestWriter.

Jump to

Keyboard shortcuts

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