logger

package
v1.0.2 Latest Latest
Warning

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

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

Documentation

Overview

Package logger defines an interface for adding a structured logger to a context and retrieving it again. The fallback when a context doesn't have a logger is the global klog logger.

This uses the same context key as logr and thus is compatible with code that uses that interface. The difference is that the Get function here never returns nil.

Also contains an extension of klog.KObj which includes the type of the object in the log output.

Index

Constants

This section is empty.

Variables

View Source
var (
	KObj = klog.KObj
	KRef = klog.KRef
)

Functions

func CapacityRef added in v1.0.0

func CapacityRef(size int64) *resource.Quantity

CapacityRef returns an object that pretty-prints the given number of bytes.

func Get

func Get(ctx context.Context) logr.Logger

Get returns the structured logger stored in the context or (if not set) a klog based logger.

func Set

func Set(ctx context.Context, logger logr.Logger) context.Context

Set returns a context with the given structured logger added to the given context.

func WithName added in v1.0.0

func WithName(ctx context.Context, name string) (context.Context, logr.Logger)

WithName updates the logger in the context and returns the new logger and context.

Types

type ObjectRefWithType

type ObjectRefWithType struct {
	klog.ObjectRef
	Type string `json:"type,omitempty"`
}

ObjectRef references a kubernetes object

func KObjWithType

func KObjWithType(obj klog.KMetadata) ObjectRefWithType

KObj returns ObjectRefWithType from ObjectMeta

func (ObjectRefWithType) String

func (ref ObjectRefWithType) String() string

type Options

type Options struct {
	logs.Options
}

Options is a wrapper around Options which makes it usable with flags.Var.

func NewFlag

func NewFlag() *Options

func (*Options) Set

func (f *Options) Set(value string) error

func (*Options) String

func (f *Options) String() string

Directories

Path Synopsis
Package testinglogger contains an implementation of the logr interface which is logging through a function like testing.TB.Log function.
Package testinglogger contains an implementation of the logr interface which is logging through a function like testing.TB.Log function.

Jump to

Keyboard shortcuts

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