log

package
v1.29.12 Latest Latest
Warning

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

Go to latest
Published: Feb 10, 2025 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultFormat         = Text
	DefaultFlushFrequency = 5 * time.Second
)
View Source
const (
	TimeKey      = slog.TimeKey
	LevelKey     = slog.LevelKey
	VerbosityKey = "v"
)

Variables

This section is empty.

Functions

func Background

func Background() logr.Logger

Background returns the background logger. Current implementation uses klog as the background logger.

func BindCLIFlags added in v1.29.12

func BindCLIFlags(fs *pflag.FlagSet)

func Flush added in v1.29.12

func Flush()

Flush flushes logs immediately.

func FromContextOrBackground

func FromContextOrBackground(ctx context.Context) logr.Logger

FromContextOrBackground returns a logger from the context if it exists, otherwise it returns a background logger. Current implementation uses klog as the background logger.

func NewContext

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

NewContext returns a new context with the provided logger.

func Noop

func Noop() logr.Logger

Noop returns a logger that discards all log messages.

func Setup added in v1.29.12

func Setup(opts *Options)

Setup initializes the logging system.

func SetupError added in v1.29.12

func SetupError(msg string, args ...any)

func ValueAsMap

func ValueAsMap(value any) map[string]any

ValueAsMap converts a value to a map[string]any. It returns a map with an "error" key if the conversion fails. NOTE:

It should ONLY be used when the default klog formatter failed to serialize the value in JSON format.
Protobuf messages had implemented `String()` method, which the value is hard to read. Use this method to bypass instead.

Types

type Format added in v1.29.12

type Format string
const (
	JSON Format = "json"
	Text Format = "text"
)

type Options added in v1.29.12

type Options struct {
	Format         Format
	FlushFrequency time.Duration
}

func OptionsFromCLIFlags added in v1.29.12

func OptionsFromCLIFlags(fs *pflag.FlagSet) *Options

type SLogJSONHandler added in v1.29.12

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

func NewJSONHandler added in v1.29.12

func NewJSONHandler(w io.Writer, opts *slog.HandlerOptions) *SLogJSONHandler

func (*SLogJSONHandler) Enabled added in v1.29.12

func (h *SLogJSONHandler) Enabled(ctx context.Context, level slog.Level) bool

func (*SLogJSONHandler) Handle added in v1.29.12

func (h *SLogJSONHandler) Handle(ctx context.Context, record slog.Record) error

func (*SLogJSONHandler) WithAttrs added in v1.29.12

func (h *SLogJSONHandler) WithAttrs(attrs []slog.Attr) slog.Handler

func (*SLogJSONHandler) WithGroup added in v1.29.12

func (h *SLogJSONHandler) WithGroup(name string) slog.Handler

Jump to

Keyboard shortcuts

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