log

package module
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2020 License: MPL-2.0 Imports: 9 Imported by: 115

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Default = Logger{StreamLogger{
		W:   os.Stderr,
		Fmt: LineFormatter,
	}}
	Discard = Logger{StreamLogger{
		W:   ioutil.Discard,
		Fmt: func(Msg) []byte { return nil },
	}}
)
View Source
var (
	Debug    = Level{1, "DEBUG"}
	Info     = Level{2, "INFO"}
	Warning  = Level{3, "WARN"}
	Error    = Level{4, "ERROR"}
	Critical = Level{5, "CRIT"}
	// Will this get special treatment? Not yet.
	Fatal = Level{6, "FATAL"}
)
View Source
var Fstr = Fmsg

Functions

func LineFormatter

func LineFormatter(msg Msg) []byte

func Print

func Print(a ...interface{})

Prints the arguments to the Default Logger.

func Printf

func Printf(format string, a ...interface{})

Types

type ByteFormatter

type ByteFormatter func(Msg) []byte

type Level

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

func (Level) LessThan

func (l Level) LessThan(r Level) bool

func (Level) LogString

func (l Level) LogString() string

type Logger

type Logger struct {
	LoggerImpl
}

Logger is a helper wrapping LoggerImpl.

func (Logger) FilterLevel

func (l Logger) FilterLevel(minLevel Level) Logger

func (Logger) Print

func (l Logger) Print(v ...interface{})

Helper for compatibility with "log".Logger.

func (Logger) Printf

func (l Logger) Printf(format string, a ...interface{})

Helper for compatibility with "log".Logger.

func (Logger) WithDefaultLevel

func (l Logger) WithDefaultLevel(level Level) Logger

func (Logger) WithFilter

func (l Logger) WithFilter(f func(Msg) bool) Logger

Returns a new logger that suppresses further propagation for messages if `f` returns false.

func (Logger) WithMap

func (l Logger) WithMap(f func(Msg) Msg) Logger

Returns a logger that for a given message propagates the result of `f` instead.

func (Logger) WithText

func (l Logger) WithText(f func(Msg) string) Logger

func (Logger) WithValues

func (l Logger) WithValues(v ...interface{}) Logger

Returns a logger that adds the given values to logged messages.

type LoggerFunc

type LoggerFunc func(Msg)

LoggerFunc is a helper type that implements LoggerImpl from just a logging function.

func (LoggerFunc) Log

func (me LoggerFunc) Log(m Msg)

type LoggerImpl

type LoggerImpl interface {
	Log(Msg)
}

LoggerImpl is the minimal interface for Logger.

type Msg

type Msg struct {
	MsgImpl
}

func Call

func Call() Msg

func Fmsg

func Fmsg(format string, a ...interface{}) Msg

func Str

func Str(s string) (m Msg)

func (Msg) Add

func (m Msg) Add(key, value interface{}) Msg

func (Msg) AddValue

func (m Msg) AddValue(v interface{}) Msg

func (Msg) AddValues

func (m Msg) AddValues(v ...interface{}) Msg

func (Msg) GetByKey

func (m Msg) GetByKey(key interface{}) (value interface{}, ok bool)

func (Msg) GetLevel

func (m Msg) GetLevel() (l Level, ok bool)

func (Msg) GetValueByType

func (m Msg) GetValueByType(p interface{}) bool

func (Msg) HasValue

func (m Msg) HasValue(v interface{}) (has bool)

func (Msg) Log

func (m Msg) Log(l Logger) Msg

rename sink

func (Msg) SetLevel

func (m Msg) SetLevel(level Level) Msg

func (Msg) Skip

func (m Msg) Skip(skip int) Msg

func (Msg) String

func (me Msg) String() string

func (Msg) With

func (m Msg) With(key, value interface{}) Msg

func (Msg) WithText

func (m Msg) WithText(f func(Msg) string) Msg

func (Msg) WithValues

func (m Msg) WithValues(v ...interface{}) Msg

TODO: What ordering should be applied to the values here, per MsgImpl.Values. For now they're traversed in order of the slice.

type MsgImpl

type MsgImpl interface {
	// Returns the message text. Allows for lazy evaluation/prefixing etc.
	Text() string
	// Sets the program counters in pc. Having it in the interface may allow us to cache/freeze them
	// for serialization etc.
	Callers(skip int, pc []uintptr) int
	// Iterates over the values as added LIFO.
	Values(callback iter.Callback)
}

The minimal interface required for the Msg helper/wrapper to operate on.

type StreamLogger

type StreamLogger struct {
	W   io.Writer
	Fmt ByteFormatter
}

func (StreamLogger) Log

func (me StreamLogger) Log(msg Msg)

Jump to

Keyboard shortcuts

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