log

package module
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Jan 27, 2022 License: MPL-2.0 Imports: 8 Imported by: 113 modules, 219 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DefaultHandler = StreamHandler{
		W:   os.Stderr,
		Fmt: LineFormatter,
	}
	Default = Logger{

		Handlers: []Handler{DefaultHandler},
		// contains filtered or unexported fields
	}
	DiscardHandler = StreamHandler{
		W:   ioutil.Discard,
		Fmt: func(Record) []byte { return nil },
	}
)
View Source
var (
	NotSet   = Level{0}
	Debug    = Level{1}
	Info     = Level{2}
	Warning  = Level{3}
	Error    = Level{4}
	Critical = Level{5}
)
View Source
var (
	Panicf = log.Panicf
	Fatalf = log.Fatalf
	Fatal  = log.Fatal
)

Deprecated: Logging shouldn't include control flow.

View Source
var Fstr = Fmsg

Functions

func Levelf added in v0.10.0

func Levelf(level Level, format string, a ...interface{})

func LineFormatter

func LineFormatter(msg Record) []byte

func Print

func Print(a ...interface{})

Prints the arguments to the Default Logger.

func Printf

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

func Println added in v0.11.0

func Println(a ...interface{})

Types

type ByteFormatter

type ByteFormatter func(Record) []byte

type Handler added in v0.11.0

type Handler interface {
	Handle(Record)
}

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 {
	Handlers []Handler
	// contains filtered or unexported fields
}

Logger is a helper wrapping LoggerImpl.

func (Logger) FilterLevel

func (l Logger) FilterLevel(minLevel Level) Logger

func (Logger) IsEnabledFor added in v0.11.0

func (l Logger) IsEnabledFor(level Level) bool

func (Logger) IsZero added in v0.9.0

func (l Logger) IsZero() bool

func (Logger) LazyLog added in v0.11.0

func (l Logger) LazyLog(level Level, f func() Msg)

func (Logger) LazyLogDefaultLevel added in v0.11.0

func (l Logger) LazyLogDefaultLevel(f func() Msg)

func (Logger) Levelf added in v0.11.0

func (l Logger) Levelf(level Level, format string, a ...interface{})

func (Logger) Log added in v0.11.0

func (l Logger) Log(m Msg)

func (Logger) LogLevel added in v0.11.0

func (l Logger) LogLevel(level Level, m Msg)

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) Println added in v0.11.0

func (l Logger) Println(a ...interface{})

func (Logger) SkipCallers added in v0.10.0

func (l Logger) SkipCallers(skip int) Logger

func (Logger) WithContextText added in v0.8.0

func (l Logger) WithContextText(s string) Logger

func (Logger) WithContextValue added in v0.8.0

func (l Logger) WithContextValue(v interface{}) Logger

func (Logger) WithDefaultLevel

func (l Logger) WithDefaultLevel(level Level) Logger

func (Logger) WithMap

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

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

func (Logger) WithNames added in v0.11.0

func (l Logger) WithNames(names ...string) Logger

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 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) HasValue

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

func (Msg) Log

func (m Msg) Log(l Logger) Msg

rename sink

func (Msg) LogLevel added in v0.11.0

func (m Msg) LogLevel(level Level, l Logger) 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 valueIterCallback)
}

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

type Record added in v0.11.0

type Record struct {
	Msg
	Level Level
	Names []string
}

type Rule added in v0.11.0

type Rule func(names []string) (level Level, matched bool)

func ContainsAllNames added in v0.11.0

func ContainsAllNames(all []string, level Level) Rule

type StreamHandler added in v0.11.0

type StreamHandler struct {
	W   io.Writer
	Fmt ByteFormatter
}

func (StreamHandler) Handle added in v0.11.0

func (me StreamHandler) Handle(r Record)

Jump to

Keyboard shortcuts

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