v1.5.1 Latest Latest

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

Go to latest
Published: Sep 13, 2023 License: MIT Imports: 7 Imported by: 15



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.


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.



This section is empty.


View Source
var ErrIllegalLevel = errors.New("illegal level")

ErrIllegalLevel represents that an illegal level.Level value/name was provided.


This section is empty.


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. This 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 notice 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 no 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 {

	// SetLevel modifies the current level to the given one.

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

type Names added in v1.3.0

type Names interface {
	// ToName converts a given level.Level to a human-readable name. If this
	// level is unknown by this instance an error is returned. Most likely
	// ErrIllegalLevel.
	ToName(Level) (string, error)

	// ToLevel converts a given human-readable name to a level.Level. If this
	// name is unknown by this instance an error is returned. Most likely
	// ErrIllegalLevel.
	ToLevel(string) (Level, error)

Names is used to make readable names out of level.Level or the other way around.

func NewNamesFacade added in v1.3.0

func NewNamesFacade(provider func() Names) Names

NewNamesFacade creates a facade of Names using the given provider.

type NamesAware added in v1.3.0

type NamesAware interface {
	// GetLevelNames returns an instance of level.Names that support by
	// formatting levels in a human-readable format.
	GetLevelNames() Names

NamesAware represents an object that is aware of Names.

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