mustlog

package module
v0.0.0-...-1fcafdc Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2017 License: MIT Imports: 1 Imported by: 0

README

MustLog GoDoc Go Report Card

An error-less go-kit/log extension.

MustLogger

MustLogger extends log.Logger with Must, an error-less version of Log.

mustLogger := NewMustLogger(&errLogger{}, func(err error, keyvals ...interface{}) {
    fmt.Println("failed to log:", err)
})
mustLogger.Log("k", "v")
mustLogger.Log(poison, "poison")

mustLogger.Must("k", "v")
mustLogger.Must(poison, "poison")

Output:

k v
k v
failed to log: poisoned

MustContext

MustContext extends log.Context to implement MustLogger.

mustContext := NewMustContext(&errLogger{}, func(err error, keyvals ...interface{}) {
    fmt.Println("failed to log:", err)
})

mustContext.Must("k", "v")
mustContext.Must(poison, "poison")

mustContext = mustContext.With("withK", "withV")
mustContext.Must("k", "v")
mustContext.Must(poison, "poison")

mustContext = mustContext.WithPrefix("prefixK", "prefixV")
mustContext.Must("k", "v")
mustContext.Must(poison, "poison")

Output:

k v
failed to log: poisoned
withK withV k v
failed to log: poisoned
prefixK prefixV withK withV k v
failed to log: poisoned

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MustContext

type MustContext struct {
	*log.Context
	// contains filtered or unexported fields
}

MustContext extends log.Context to implement MustLogger.

Example
mustContext := NewMustContext(&errLogger{}, func(err error, keyvals ...interface{}) {
	fmt.Println("failed to log:", err)
})

mustContext.Must("k", "v")
mustContext.Must(poison, "poison")

mustContext = mustContext.With("withK", "withV")
mustContext.Must("k", "v")
mustContext.Must(poison, "poison")

mustContext = mustContext.WithPrefix("prefixK", "prefixV")
mustContext.Must("k", "v")
mustContext.Must(poison, "poison")
Output:

k v
failed to log: poisoned
withK withV k v
failed to log: poisoned
prefixK prefixV withK withV k v
failed to log: poisoned

func NewMustContext

func NewMustContext(l log.Logger, onErr func(error, ...interface{})) *MustContext

func (*MustContext) Must

func (c *MustContext) Must(keyvals ...interface{})

func (*MustContext) With

func (c *MustContext) With(keyvals ...interface{}) *MustContext

func (*MustContext) WithPrefix

func (c *MustContext) WithPrefix(keyvals ...interface{}) *MustContext

type MustLogger

type MustLogger struct {
	log.Logger
	// contains filtered or unexported fields
}

MustLogger extends log.Logger with Must, an error-less version of Log.

Example
mustLogger := NewMustLogger(&errLogger{}, func(err error, keyvals ...interface{}) {
	fmt.Println("failed to log:", err)
})
mustLogger.Log("k", "v")
mustLogger.Log(poison, "poison")

mustLogger.Must("k", "v")
mustLogger.Must(poison, "poison")
Output:

k v
k v
failed to log: poisoned

func NewMustLogger

func NewMustLogger(logger log.Logger, onErr func(error, ...interface{})) *MustLogger

func (*MustLogger) Must

func (m *MustLogger) Must(keyvals ...interface{})

Jump to

Keyboard shortcuts

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