logger

package
v0.9.1 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2024 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	FatalLevel   = infoLevelShift - 2
	WarnLevel    = infoLevelShift - 1
	InfoLevel    = infoLevelShift
	DebugLevel   = infoLevelShift + 1
	VerboseLevel = infoLevelShift + 2
)

Log Level Mapping: | NumaLogger semantic | logr verbosity | zerolog | | ------------------- | --------------- | -------------- | | fatal | 1 | 4 | | error | error (NA) | 3 | | warn | 2 | 2 | | info | 3 | 1 | | debug | 4 | 0 | | verbose | 5 | -2 (custom) |

Variables

This section is empty.

Functions

func SetBaseLogger

func SetBaseLogger(nl *NumaLogger)

SetBaseLogger is intended to be set once when application starts

func WithLogger

func WithLogger(ctx context.Context, logger *NumaLogger) context.Context

WithLogger returns a copy of parent context in which the value associated with logger key is the supplied logger.

Types

type LogSink

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

LogSink implements logr.LogSink using zerolog as base logger.

func (*LogSink) Enabled

func (ls *LogSink) Enabled(level int) bool

Enabled tests whether this LogSink is enabled at the specified V-level and per-package.

func (*LogSink) Error

func (ls *LogSink) Error(err error, msg string, keysAndValues ...any)

Error logs an error, with the given message, and key/value pairs as context.

func (*LogSink) Info

func (ls *LogSink) Info(level int, msg string, keysAndValues ...any)

Info logs a non-error message (msg) with the given key/value pairs as context and the specified level.

func (*LogSink) Init

func (ls *LogSink) Init(ri logr.RuntimeInfo)

Init receives optional information about the logr library and sets the call depth accordingly.

func (LogSink) WithCallDepth

func (ls LogSink) WithCallDepth(depth int) logr.LogSink

WithCallDepth returns a LogSink that will offset the call stack by the specified number of frames when logging call site information.

func (LogSink) WithName

func (ls LogSink) WithName(name string) logr.LogSink

WithName returns a new LogSink with the specified name appended.

func (LogSink) WithValues

func (ls LogSink) WithValues(keysAndValues ...any) logr.LogSink

WithValues returns a new LogSink with additional key/value pairs.

type NumaLogger

type NumaLogger struct {
	LogrLogger *logr.Logger
	LogLevel   int
}

NumaLogger is the struct containing a pointer to a logr.Logger instance.

func FromContext

func FromContext(ctx context.Context) *NumaLogger

FromContext returns the logger in the context. If there is no logger in context, a new one is created.

func GetBaseLogger

func GetBaseLogger() *NumaLogger

Get the standard NumaLogger with current Log Level - deep copy it in case user modifies it

func New

func New() *NumaLogger

New returns a new NumaLogger with a logr.Logger instance with a default setup for zerolog, os.Stdout writer, and info level.

func (*NumaLogger) Debug

func (nl *NumaLogger) Debug(msg string, keysAndValues ...any)

Debug logs a debug-level message with optional key/value pairs.

func (*NumaLogger) Debugf

func (nl *NumaLogger) Debugf(msg string, args ...any)

Debugf logs a debug-level formatted message with args.

func (*NumaLogger) DeepCopy

func (in *NumaLogger) DeepCopy() *NumaLogger

func (*NumaLogger) Error

func (nl *NumaLogger) Error(err error, msg string, keysAndValues ...any)

Error logs an error with a message and optional key/value pairs.

func (*NumaLogger) Errorf

func (nl *NumaLogger) Errorf(err error, msg string, args ...any)

Errorf logs an error with a formatted message with args.

func (*NumaLogger) Fatal

func (nl *NumaLogger) Fatal(err error, msg string, keysAndValues ...any)

Fatal logs an error with a message and optional key/value pairs. Then, exits with code 1.

func (*NumaLogger) Fatalf

func (nl *NumaLogger) Fatalf(err error, msg string, args ...any)

Fatalf logs an error with a formatted message with args. Then, exits with code 1.

func (*NumaLogger) Info

func (nl *NumaLogger) Info(msg string, keysAndValues ...any)

Info logs an info-level message with optional key/value pairs.

func (*NumaLogger) Infof

func (nl *NumaLogger) Infof(msg string, args ...any)

Infof logs an info-level formatted message with args.

func (*NumaLogger) SetLevel

func (nl *NumaLogger) SetLevel(level int)

SetLevel sets/changes the log level.

func (*NumaLogger) Verbose

func (nl *NumaLogger) Verbose(msg string, keysAndValues ...any)

Verbose logs a verbose-level message with optional key/value pairs.

func (*NumaLogger) Verbosef

func (nl *NumaLogger) Verbosef(msg string, args ...any)

Verbosef logs a verbose-level formatted message with args.

func (*NumaLogger) Warn

func (nl *NumaLogger) Warn(msg string, keysAndValues ...any)

Warn logs a warning-level message with optional key/value pairs.

func (*NumaLogger) Warnf

func (nl *NumaLogger) Warnf(msg string, args ...any)

Warn logs a warning-level formatted message with args.

func (*NumaLogger) WithCallDepth

func (nl *NumaLogger) WithCallDepth(depth int) *NumaLogger

WithCallDepth returns a Logger instance that offsets the call stack by the specified number of frames when logging call site information.

func (*NumaLogger) WithName

func (nl *NumaLogger) WithName(name string) *NumaLogger

WithName appends a given name to the logger.

func (*NumaLogger) WithValues

func (nl *NumaLogger) WithValues(keysAndValues ...any) *NumaLogger

WithValues appends additional key/value pairs to the logger.

Jump to

Keyboard shortcuts

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