logging

package
v0.2.4 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2024 License: BSD-3-Clause Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrLoggingInstance = errors.New("errLoggingInstance")

ErrLoggingInstance is the error returned when encountering issues registering, removing, fetching, or updating logging instances from the logging Manager.

Functions

func DefaultFormatter

func DefaultFormatter(i Instance, l, m string) string

DefaultFormatter is the default logging instance formatter -- this formatter simply adds colors to the log message based on log level.

func DefaultKlogFormatter

func DefaultKlogFormatter(i Instance, l, m string) string

DefaultKlogFormatter is the default logging instance formatter for *klog* logs. Ortica redirects klog logs through its own logging manager to give us more control, this formatter is applied by default to those messages only.

func InitManager added in v0.0.13

func InitManager(options ...Option)

InitManager initializes the logging manager with the provided options. It does nothing if the manager has already been initialized. This may be a bit awkward but since this is not expected to be used by anything but clabernetes and it works for us, it works!

func StdErrLog added in v0.0.13

func StdErrLog(a ...any)

StdErrLog writes `a` to stderr, it ignores failures.

func ValidateLogLevel

func ValidateLogLevel(l string) (string, error)

ValidateLogLevel accepts a string l and returns a case-normalized log level corresponding to l, if l is a valid log level, or an error.

Types

type FakeInstance added in v0.0.17

type FakeInstance struct{}

FakeInstance is a fake logging instance that does nothing.

func (*FakeInstance) Critical added in v0.0.17

func (i *FakeInstance) Critical(f string)

func (*FakeInstance) Criticalf added in v0.0.17

func (i *FakeInstance) Criticalf(f string, a ...interface{})

func (*FakeInstance) Debug added in v0.0.17

func (i *FakeInstance) Debug(f string)

func (*FakeInstance) Debugf added in v0.0.17

func (i *FakeInstance) Debugf(f string, a ...interface{})

func (*FakeInstance) Fatal added in v0.0.17

func (i *FakeInstance) Fatal(f string)

func (*FakeInstance) Fatalf added in v0.0.17

func (i *FakeInstance) Fatalf(f string, a ...interface{})

func (*FakeInstance) GetLevel added in v0.0.17

func (i *FakeInstance) GetLevel() string

func (*FakeInstance) GetName added in v0.0.17

func (i *FakeInstance) GetName() string

func (*FakeInstance) Info added in v0.0.17

func (i *FakeInstance) Info(f string)

func (*FakeInstance) Infof added in v0.0.17

func (i *FakeInstance) Infof(f string, a ...interface{})

func (*FakeInstance) Warn added in v0.0.17

func (i *FakeInstance) Warn(f string)

func (*FakeInstance) Warnf added in v0.0.17

func (i *FakeInstance) Warnf(f string, a ...interface{})

func (*FakeInstance) Write added in v0.0.17

func (i *FakeInstance) Write(p []byte) (n int, err error)

type Formatter

type Formatter func(i Instance, l, m string) string

Formatter is a type representing a valid logging formatter function. It should accept a logging instance, a level string, and a message string, returning a formatted message string.

type Instance

type Instance interface {
	Debug(f string)
	Debugf(f string, a ...interface{})
	Info(f string)
	Infof(f string, a ...interface{})
	Warn(f string)
	Warnf(f string, a ...interface{})
	Critical(f string)
	Criticalf(f string, a ...interface{})
	Fatal(f string)
	Fatalf(f string, a ...interface{})
	// Write implements io.Writer so that an instance can be used most places. Messages received
	// via Write will always have the current formatter applied, and all messages will be queued
	// for egress unless this logging instance's level is Disabled.
	Write(p []byte) (n int, err error)
	GetName() string
	GetLevel() string
}

Instance is a logging instance managed by the Manager.

type Manager

type Manager interface {
	SetLoggerFormatter(name string, formatter Formatter) error
	SetLoggerFormatterAllInstances(formatter Formatter)
	SetLoggerLevelAllInstances(level string)
	SetLoggerLevel(name, level string) error
	RegisterLogger(name, level string) error
	RegisterAndGetLogger(name, level string) (Instance, error)
	MustRegisterAndGetLogger(name, level string) Instance
	GetLogger(name string) (Instance, error)
	DeleteLogger(name string)
	Flush()
}

Manager is the interface representing the global logging manager singleton, this interface defines the ways to interact with this object.

func GetManager

func GetManager() Manager

GetManager returns the global logging Manager. Panics if the logging manager has *not* been initialized (via InitManager).

type Option added in v0.0.13

type Option func(m *manager)

Option is a functional option type for applying options to the logging Manager.

func WithLogger added in v0.0.13

func WithLogger(logger func(...interface{})) Option

WithLogger appends a logger (a function that accepts an interface) to the logging Manager's set of loggers.

Jump to

Keyboard shortcuts

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