level

package
v0.20.0 Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2021 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package native/level provides additions of slf4g/level for the native implementations.

Index

Constants

This section is empty.

Variables

View Source
var DefaultNames = NewNames()

DefaultNames is the default instance of Names which should cover the most of the cases.

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

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

Functions

This section is empty.

Types

type Colorizer added in v0.9.0

type Colorizer interface {

	// ColorizeByLevel is colorizing the given input for the given level.Level.
	ColorizeByLevel(lvl level.Level, input string) string
}

Colorizer is colorizing inputs for given levels by ANSI escape codes. See: https://en.wikipedia.org/wiki/ANSI_escape_code

var DefaultColorizer Colorizer = ColorizerMap{
	level.Trace: `�[30;1m`,
	level.Debug: `�[36;1m`,
	level.Info:  `�[34;1m`,
	level.Warn:  `�[33;1m`,
	level.Error: `�[31;1m`,
	level.Fatal: `�[35;1m`,
}

DefaultColorizer is the default instance of Colorizer which should cover the most of the cases.

func NewColorizerFacade added in v0.9.0

func NewColorizerFacade(provider func() Colorizer) Colorizer

NewColorizerFacade creates a facade of Colorizer using the given provider.

func NoopColorizer added in v0.9.0

func NoopColorizer() Colorizer

NoopColorizer provides a noop implementation of Colorizer.

type ColorizerMap added in v0.9.0

type ColorizerMap map[level.Level]string

ColorizerMap is an implementation of Colorizer which simply holds for configured level.Level an ANSI escape code for colorizing. If there is no level.Level configured it defaults to a simple grey.

func (ColorizerMap) ColorizeByLevel added in v0.9.0

func (l ColorizerMap) ColorizeByLevel(lvl level.Level, what string) string

ColorizeByLevel implements Colorizer.ColorizeByLevel()

type Named added in v0.9.0

type Named interface {
	Unwrap() *level.Level

	encoding.TextMarshaler
	encoding.TextUnmarshaler
	flag.Getter
}

Named represents a level.Level in a human readable format and provides the possibility to marshal and get used with flag (or compatible) packages.

func AsNamed added in v0.9.0

func AsNamed(in *level.Level, names Names) Named

AsNamed wraps the given level.Level into Named to it in a human readable format and provides the possibility to marshal and get used with flag (or compatible) packages.

type Names

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.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.Level, error)
}

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

func NewNames added in v0.9.0

func NewNames() Names

NewNames creates a new default instance of a Names implementation.

func NewNamesFacade added in v0.5.0

func NewNamesFacade(provider func() Names) Names

NewNamesFacade creates a facade of Names using the given provider.

type NamesAware

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.

Jump to

Keyboard shortcuts

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