xlog

package module
v0.0.0-...-5bee1ff Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2023 License: Apache-2.0 Imports: 11 Imported by: 7

README

xlog

Logging library

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (

	// ExitFlushTimeout is the timeout that klog has traditionally used during
	// calls like Fatal or Exit when flushing log data right before exiting.
	// Applications that replace those calls and do not have some specific
	// requirements like "exit immediately" can use this value as parameter
	// for FlushAndExit.
	//
	// Can be set for testing purpose or to change the application's
	// default.
	ExitFlushTimeout = 10 * time.Second

	// OsExit is the function called by FlushAndExit to terminate the program.
	//
	// Can be set for testing purpose or to change the application's
	// default behavior. Note that the function should not simply return
	// because callers of functions like Fatal will not expect that.
	OsExit = os.Exit
)
View Source
var (
	// New is an alias for logr.New.
	New = logr.New
)

Functions

func ClearLogger

func ClearLogger()

ClearLogger removes a backing Logger implementation if one was set earlier with SetLogger.

Modifying the logger is not thread-safe and should be done while no other goroutines invoke log calls, usually during program initialization.

func Error

func Error(args ...interface{})

Error logs to the ERROR, WARNING, and INFO logs. Arguments are handled in the manner of fmt.Print; a newline is appended if missing.

func ErrorDepth

func ErrorDepth(depth int, args ...interface{})

ErrorDepth acts as Error but uses depth to determine which call frame to log. ErrorDepth(0, "msg") is the same as Error("msg").

func ErrorS

func ErrorS(err error, msg string, keysAndValues ...interface{})

ErrorS structured logs to the ERROR, WARNING, and INFO logs. the err argument used as "err" field of log line. The msg argument used to add constant description to the log line. The key/value pairs would be join by "=" ; a newline is always appended.

Basic examples: >> klog.ErrorS(err, "Failed to update pod status") output: >> E1025 00:15:15.525108 1 controller_utils.go:114] "Failed to update pod status" err="timeout"

func ErrorSDepth

func ErrorSDepth(depth int, err error, msg string, keysAndValues ...interface{})

ErrorSDepth acts as ErrorS but uses depth to determine which call frame to log. ErrorSDepth(0, "msg") is the same as ErrorS("msg").

func Errorf

func Errorf(format string, args ...interface{})

Errorf logs to the ERROR, WARNING, and INFO logs. Arguments are handled in the manner of fmt.Printf; a newline is appended if missing.

func ErrorfDepth

func ErrorfDepth(depth int, format string, args ...interface{})

ErrorfDepth acts as Errorf but uses depth to determine which call frame to log. ErrorfDepth(0, "msg", args...) is the same as Errorf("msg", args...).

func Errorln

func Errorln(args ...interface{})

Errorln logs to the ERROR, WARNING, and INFO logs. Arguments are handled in the manner of fmt.Println; a newline is always appended.

func ErrorlnDepth

func ErrorlnDepth(depth int, args ...interface{})

ErrorlnDepth acts as Errorln but uses depth to determine which call frame to log. ErrorlnDepth(0, "msg") is the same as Errorln("msg").

func Fatal

func Fatal(args ...interface{})

Fatal logs to the FATAL, ERROR, WARNING, and INFO logs, prints stack trace(s), then calls OsExit(255).

Stderr only receives a dump of the current goroutine's stack trace. Log files, if there are any, receive a dump of the stack traces in all goroutines.

Callers who want more control over handling of fatal events may instead use a combination of different functions:

  • some info or error logging function, optionally with a stack trace value generated by github.com/go-logr/lib/dbg.Backtrace
  • Flush to flush pending log data
  • panic, os.Exit or returning to the caller with an error

Arguments are handled in the manner of fmt.Print; a newline is appended if missing.

func FatalDepth

func FatalDepth(depth int, args ...interface{})

FatalDepth acts as Fatal but uses depth to determine which call frame to log. FatalDepth(0, "msg") is the same as Fatal("msg").

func Fatalf

func Fatalf(format string, args ...interface{})

Fatalf logs to the FATAL, ERROR, WARNING, and INFO logs, including a stack trace of all running goroutines, then calls OsExit(255). Arguments are handled in the manner of fmt.Printf; a newline is appended if missing.

func FatalfDepth

func FatalfDepth(depth int, format string, args ...interface{})

FatalfDepth acts as Fatalf but uses depth to determine which call frame to log. FatalfDepth(0, "msg", args...) is the same as Fatalf("msg", args...).

func Fatalln

func Fatalln(args ...interface{})

Fatalln logs to the FATAL, ERROR, WARNING, and INFO logs, including a stack trace of all running goroutines, then calls OsExit(255). Arguments are handled in the manner of fmt.Println; a newline is always appended.

func FatallnDepth

func FatallnDepth(depth int, args ...interface{})

FatallnDepth acts as Fatalln but uses depth to determine which call frame to log. FatallnDepth(0, "msg") is the same as Fatalln("msg").

func Flush

func Flush()

Flush flushes all pending log I/O.

func FlushAndExit

func FlushAndExit(flushTimeout time.Duration, exitCode int)

FlushAndExit flushes log data for a certain amount of time and then calls os.Exit. Combined with some logging call it provides a replacement for traditional calls like Fatal or Exit.

func GetSeverityNames

func GetSeverityNames() []string

func GlobalLogger

func GlobalLogger() *logWriter

func Info

func Info(args ...interface{})

Info logs to the INFO log. Arguments are handled in the manner of fmt.Print; a newline is appended if missing.

func InfoDepth

func InfoDepth(depth int, args ...interface{})

InfoDepth acts as Info but uses depth to determine which call frame to log. InfoDepth(0, "msg") is the same as Info("msg").

func InfoS

func InfoS(msg string, keysAndValues ...interface{})

InfoS structured logs to the INFO log. The msg argument used to add constant description to the log line. The key/value pairs would be join by "=" ; a newline is always appended.

Basic examples: >> klog.InfoS("Pod status updated", "pod", "kubedns", "status", "ready") output: >> I1025 00:15:15.525108 1 controller_utils.go:116] "Pod status updated" pod="kubedns" status="ready"

func InfoSDepth

func InfoSDepth(depth int, msg string, keysAndValues ...interface{})

InfoSDepth acts as InfoS but uses depth to determine which call frame to log. InfoSDepth(0, "msg") is the same as InfoS("msg").

func Infof

func Infof(format string, args ...interface{})

Infof logs to the INFO log. Arguments are handled in the manner of fmt.Printf; a newline is appended if missing.

func InfofDepth

func InfofDepth(depth int, format string, args ...interface{})

InfofDepth acts as Infof but uses depth to determine which call frame to log. InfofDepth(0, "msg", args...) is the same as Infof("msg", args...).

func Infoln

func Infoln(args ...interface{})

Infoln logs to the INFO log. Arguments are handled in the manner of fmt.Println; a newline is always appended.

func InfolnDepth

func InfolnDepth(depth int, args ...interface{})

InfolnDepth acts as Infoln but uses depth to determine which call frame to log. InfolnDepth(0, "msg") is the same as Infoln("msg").

func InitGlobalLogger

func InitGlobalLogger()

func NewContext

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

NewContext returns logr.NewContext(ctx, logger) when contextual logging is enabled, otherwise ctx.

func SetFile

func SetFile(p string)

func SetFileMaxAgeDay

func SetFileMaxAgeDay(p int)

func SetFileMaxBackups

func SetFileMaxBackups(p int)

func SetFileMaxSizeMB

func SetFileMaxSizeMB(p int)

func SetLogger

func SetLogger(logger logr.Logger)

To remove a backing logr implemention, use ClearLogger. Setting an empty logger with SetLogger(logr.Logger{}) does not work.

Modifying the logger is not thread-safe and should be done while no other goroutines invoke log calls, usually during program initialization.

func SetSeverity

func SetSeverity(s severity.Severity)

func SetSeverityName

func SetSeverityName(s string)

func SetVerbosity

func SetVerbosity(v int)

func SwitchContextual

func SwitchContextual(b bool)

func Warning

func Warning(args ...interface{})

Warning logs to the WARNING and INFO logs. Arguments are handled in the manner of fmt.Print; a newline is appended if missing.

func WarningDepth

func WarningDepth(depth int, args ...interface{})

WarningDepth acts as Warning but uses depth to determine which call frame to log. WarningDepth(0, "msg") is the same as Warning("msg").

func Warningf

func Warningf(format string, args ...interface{})

Warningf logs to the WARNING and INFO logs. Arguments are handled in the manner of fmt.Printf; a newline is appended if missing.

func WarningfDepth

func WarningfDepth(depth int, format string, args ...interface{})

WarningfDepth acts as Warningf but uses depth to determine which call frame to log. WarningfDepth(0, "msg", args...) is the same as Warningf("msg", args...).

func Warningln

func Warningln(args ...interface{})

Warningln logs to the WARNING and INFO logs. Arguments are handled in the manner of fmt.Println; a newline is always appended.

func WarninglnDepth

func WarninglnDepth(depth int, args ...interface{})

WarninglnDepth acts as Warningln but uses depth to determine which call frame to log. WarninglnDepth(0, "msg") is the same as Warningln("msg").

Types

type Level

type Level int32

Level specifies a level of verbosity for V logs. *Level implements flag.Value; the -v flag is of type Level and should be modified only through the flag.Value interface.

func (*Level) Get

func (l *Level) Get() interface{}

Get is part of the flag.Getter interface.

func (*Level) Set

func (l *Level) Set(value string) error

Set is part of the flag.Value interface.

func (*Level) String

func (l *Level) String() string

String is part of the flag.Value interface.

type LogSink

type LogSink = logr.LogSink

LogSink in this package is exactly the same as logr.LogSink.

type Logger

type Logger = logr.Logger

Logger in this package is exactly the same as logr.Logger.

func Background

func Background() Logger

Background retrieves the fallback logger. It should not be called before that logger was initialized by the program and not by code that should better receive a logger via its parameters. TODO can be used as a temporary solution for such code.

func FromContext

func FromContext(ctx context.Context) Logger

FromContext retrieves a logger set by the caller or, if not set, falls back to the program's global logger (a Logger instance or xlog itself).

func LoggerWithName

func LoggerWithName(logger Logger, name string) Logger

LoggerWithName returns logger.WithName(name) when contextual logging is enabled, otherwise the logger.

func LoggerWithValues

func LoggerWithValues(logger Logger, kv ...interface{}) Logger

LoggerWithValues returns logger.WithValues(...kv) when contextual logging is enabled, otherwise the logger.

func TODO

func TODO() Logger

TODO can be used as a last resort by code that has no means of receiving a logger from its caller. FromContext or an explicit logger parameter should be used instead.

type RuntimeInfo

type RuntimeInfo = logr.RuntimeInfo

Runtimeinfo in this package is exactly the same as logr.RuntimeInfo.

type Verbose

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

Verbose is a boolean type that implements Infof (like Printf) etc. See the documentation of V for more information.

func V

func V(level Level) Verbose

func (Verbose) ErrorS

func (v Verbose) ErrorS(err error, msg string, keysAndValues ...interface{})

ErrorS is equivalent to the global Error function, guarded by the value of v. See the documentation of V for usage.

func (Verbose) Info

func (v Verbose) Info(args ...interface{})

Info is equivalent to the global Info function, guarded by the value of v. See the documentation of V for usage.

func (Verbose) InfoDepth

func (v Verbose) InfoDepth(depth int, args ...interface{})

InfoDepth is equivalent to the global InfoDepth function, guarded by the value of v. See the documentation of V for usage.

func (Verbose) InfoS

func (v Verbose) InfoS(msg string, keysAndValues ...interface{})

InfoS is equivalent to the global InfoS function, guarded by the value of v. See the documentation of V for usage.

func (Verbose) InfoSDepth

func (v Verbose) InfoSDepth(depth int, msg string, keysAndValues ...interface{})

InfoSDepth is equivalent to the global InfoSDepth function, guarded by the value of v. See the documentation of V for usage.

func (Verbose) Infof

func (v Verbose) Infof(format string, args ...interface{})

Infof is equivalent to the global Infof function, guarded by the value of v. See the documentation of V for usage.

func (Verbose) InfofDepth

func (v Verbose) InfofDepth(depth int, format string, args ...interface{})

InfofDepth is equivalent to the global InfofDepth function, guarded by the value of v. See the documentation of V for usage.

func (Verbose) Infoln

func (v Verbose) Infoln(args ...interface{})

Infoln is equivalent to the global Infoln function, guarded by the value of v. See the documentation of V for usage.

func (Verbose) InfolnDepth

func (v Verbose) InfolnDepth(depth int, args ...interface{})

InfolnDepth is equivalent to the global InfolnDepth function, guarded by the value of v. See the documentation of V for usage.

Directories

Path Synopsis
internal
lib
zapr
Package zapr defines an implementation of the github.com/go-logr/logr interfaces built on top of Zap (go.uber.org/zap).
Package zapr defines an implementation of the github.com/go-logr/logr interfaces built on top of Zap (go.uber.org/zap).

Jump to

Keyboard shortcuts

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