logger

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Dec 8, 2022 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ImportantLevel       = int(zapcore.ErrorLevel)
	InfoLevel            = int(zapcore.InfoLevel)
	DebugLevel           = int(zapcore.DebugLevel)
	PerformanceTestLevel = -128
)

Variables

This section is empty.

Functions

func GetObservedLogs

func GetObservedLogs() *observer.ObservedLogs

GetObservedLogs returns ObservedLogs object, can be used in unit tests to see if something got logged

Types

type Exit

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

Exit has an exit func, and will memorize the exit status code

func CreateExiter

func CreateExiter(exit Func) *Exit

CreateExiter returns an exiter with a custom function

func Default

func Default() *Exit

Default returns an Exit with default os.Exit() call. That means the status will never be visible, since os.Exit() stops everything.

func (*Exit) Exit

func (e *Exit) Exit(code int)

Exit calls the exiter, and then returns code as status. If e was declared, but never set (since only a test would set e), simply calls os.Exit()

func (*Exit) Status

func (e *Exit) Status() int

Status get the exit status code as memorized after the call to the exit func.

type Func

type Func func(int)

Func takes a code as exit status

type Logger

type Logger struct {
	logr.Logger
	// contains filtered or unexported fields
}

func CreateDebugLogger

func CreateDebugLogger() Logger

func CreateLogger

func CreateLogger(isDebug bool) Logger

CreateLogger creates a new logger instance isDebug: if enabled, the logger prints debug logs, otherwise it prints info level and above

func (Logger) Fatal

func (l Logger) Fatal(msg string, keysAndValues ...interface{})

Fatal logs message with important level and exits with code 1

func (Logger) FatalError

func (l Logger) FatalError(err error, msg string, keysAndValues ...interface{})

FatalError logs message and error with important level and exits with code 1

func (Logger) GetExiter

func (l Logger) GetExiter() *Exit

func (Logger) SetExiter

func (l Logger) SetExiter(exit *Exit)

SetExiter useful for debugging when the exit is set, the code won't call os.Exit($code) but will set the status on the Exit struct this is useful when you want to test if a function crashes with os.Exit(1) for example.

Jump to

Keyboard shortcuts

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