level

package
Version: v0.21.0 Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2021 License: MIT Imports: 6 Imported by: 7

Documentation

Overview

Level identifies the severity of an event to be logged. As higher ans more important is the event. Trace is the less severe and Fatal the most severe.

Customization

Different implementations of Provider could introduce more Levels. All ordinals are unique over all instances of Level. Info = 3000 will be always Info = 3000. Another Level which uses the ordinal 3000 can be just assumed as an alias to Info. Customization only means added new instances of Level. Standard levels always remains available.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Aware added in v0.7.1

type Aware interface {
	// GetLevel returns the current level.
	GetLevel() Level
}

Aware describes an object that is aware of a Level and exports its current state.

type Level

type Level uint16
const (
	// Trace defines the lowest possible level. This is usually only used
	// in cases where really detailed logs are required. For example to document
	// the whole communication with a server, including each request with its
	// headers and so on.
	Trace Level = 1000

	// Debug is used to document information which is used to debug
	// problems. These information are in regular operation mode are not
	// required; but could help once enabled to track down common issues.
	Debug Level = 2000

	// Info is the regular level where everything is logged which is of
	// interest for everybody and should be always visible and imply regular
	// operations of the system. Usually this shows that one operation succeeded
	// successfully; like a user was created.
	Info Level = 3000

	// Warn implies that something happened which failed but could be
	// recovered gracefully. In best case the user does not noticed anything.
	// But personal should investigate as soon as possible to prevent something
	// like this happening again.
	Warn Level = 4000

	// Error implies that something happened which failed and cannot be
	// recovered gracefully but it only affects one or a small amount of users
	// and the rest of the system can continue to work. Personal should
	// investigate right now to prevent such stuff happening again and recover
	// broken users.
	Error Level = 5000

	// Fatal implies that something happened which failed and cannot be
	// recovered gracefully, which might affect every user of the system. This
	// implies that the whole system is not longer operable and should/will be
	// shutdown (if possible gracefully) right now. Personal is required to
	// investigate right now to prevent such stuff happening again, bring the
	// the system back to operations and recover broken users.
	Fatal Level = 6000
)

func (Level) CompareTo

func (instance Level) CompareTo(o Level) int

CompareTo helps to compare the severity of two levels. It returns how much severe the provided Level is compared to the actual one. Bigger means more severe.

type Levels

type Levels []Level

Levels represents a slice of 0..n Level.

Additionally it implements the sort.Interface to enable to call sort.Sort to order the contents of this slice by its severity.

func (Levels) Len

func (instance Levels) Len() int

See sort.Interface

func (Levels) Less

func (instance Levels) Less(i, j int) bool

See sort.Interface

func (Levels) Swap

func (instance Levels) Swap(i, j int)

See sort.Interface

func (Levels) ToProvider added in v0.10.0

func (instance Levels) ToProvider(name string) Provider

ToProvider transforms the current Levels into a Provider instance with the given name.

type LineExtractor added in v0.7.1

type LineExtractor interface {
	ExtractLevelFromLine([]byte) (Level, error)
}

LineExtractor checks a given line for the contained Level and will return it. The implementation can decide to also return another level.

func FixedLevelExtractor added in v0.7.1

func FixedLevelExtractor(in Level) LineExtractor

FixedLevelExtractor is an implementation of LineExtractor which always returns the same Level value regardless what was in the line.

type LineExtractorFunc added in v0.7.1

type LineExtractorFunc func([]byte) (Level, error)

LineExtractorFunc like LineExtractor but as a func.

func (LineExtractorFunc) ExtractLevelFromLine added in v0.7.1

func (instance LineExtractorFunc) ExtractLevelFromLine(in []byte) (Level, error)

type MutableAware added in v0.7.1

type MutableAware interface {
	Aware

	// SetLevel modifies the current level to the given one.
	SetLevel(Level)
}

MutableAware is similar to Aware but additionally is able to modify the Level by calling SetLevel(Level).

type Provider

type Provider interface {
	GetName() string
	GetLevels() Levels
}

Provider provides all available Levels.

func GetAllProviders

func GetAllProviders() []Provider

GetAllProviders returns all knows providers registered with RegisterProvider().

func GetProvider

func GetProvider() Provider

GetProvider returns the actual Provider.

The Provider returned by this method is guarded by a facade (see NewProviderFacade()) which ensures that usages of this Provider will always call the global configured Provider depending on whether the Provider was configured before calling this method or afterwards.

func NewProviderFacade

func NewProviderFacade(provider func() Provider) Provider

NewProviderFacade creates a new facade of Provider with the given function that provides the actual Provider to use.

func RegisterProvider

func RegisterProvider(p Provider) Provider

RegisterProvider registers the given provider as a usable one. If GetProvider() is called each Provider which was registered with this method will be then taken into consideration to be returned.

It is not possible to register more than one instance of a Provider with the same name.

func SetProvider

func SetProvider(p Provider) Provider

SetProvider forces the given Provider as the actual one which will be returned when calling GetProvider(). This will lead to that each Provider registered with RegisterProvider() will be ignored.

This methods accepts also <nil>. In this case regular discovery mechanism will be enabled again when calling GetProvider().

This methods always returns the previous set value (which can be <nil>, too).

func UnregisterProvider

func UnregisterProvider(name string) Provider

UnregisterProvider is doing the exact opposite of RegisterProvider().

Jump to

Keyboard shortcuts

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