levels - ActiveState ActiveGo 1.8
...

Package levels

import "github.com/go-kit/kit/log/deprecated_levels"
Overview
Index
Examples

Overview ▾

type Levels

Levels provides a leveled logging wrapper around a logger. It has five levels: debug, info, warning (warn), error, and critical (crit). If you want a different set of levels, you can create your own levels type very easily, and you can elide the configuration.

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

Example

Code:

logger := levels.New(log.NewLogfmtLogger(os.Stdout))
logger.Debug().Log("msg", "hello")
logger.With("context", "foo").Warn().Log("err", "error")

Output:

level=debug msg=hello
level=warn context=foo err=error

func New

func New(logger log.Logger, options ...Option) Levels

New creates a new leveled logger, wrapping the passed logger.

func (Levels) Crit

func (l Levels) Crit() log.Logger

Crit returns a critical level logger.

func (Levels) Debug

func (l Levels) Debug() log.Logger

Debug returns a debug level logger.

func (Levels) Error

func (l Levels) Error() log.Logger

Error returns an error level logger.

func (Levels) Info

func (l Levels) Info() log.Logger

Info returns an info level logger.

func (Levels) Warn

func (l Levels) Warn() log.Logger

Warn returns a warning level logger.

func (Levels) With

func (l Levels) With(keyvals ...interface{}) Levels

With returns a new leveled logger that includes keyvals in all log events.

type Option

Option sets a parameter for leveled loggers.

type Option func(*Levels)

func CritValue

func CritValue(value string) Option

CritValue sets the value for the field used to indicate the critical log level. By default, the value is "crit".

func DebugValue

func DebugValue(value string) Option

DebugValue sets the value for the field used to indicate the debug log level. By default, the value is "debug".

func ErrorValue

func ErrorValue(value string) Option

ErrorValue sets the value for the field used to indicate the error log level. By default, the value is "error".

func InfoValue

func InfoValue(value string) Option

InfoValue sets the value for the field used to indicate the info log level. By default, the value is "info".

func Key

func Key(key string) Option

Key sets the key for the field used to indicate log level. By default, the key is "level".

func WarnValue

func WarnValue(value string) Option

WarnValue sets the value for the field used to indicate the warning log level. By default, the value is "warn".