logur: emperror.dev/handler/logur Index | Examples | Files

package logur

import "emperror.dev/handler/logur"

Package logur provides an error handler using a Logur compatible logger.

Index

Examples

Package Files

handler.go

type ErrorLogger Uses

type ErrorLogger interface {
    // Error logs an Error event.
    //
    // Critical events that require immediate attention.
    Error(msg string, fields ...map[string]interface{})
}

ErrorLogger is a subset of the Logur logger interface used for error logging.

type Handler Uses

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

Handler logs errors using a Logur compatible logger.

func New Uses

func New(logger ErrorLogger) *Handler

New returns a new Handler.

Code:

logger := logur.NewNoopLogger()
_ = logurhandler.New(logger)

func WithStackInfo Uses

func WithStackInfo(handler *Handler) *Handler

WithStackInfo enables annotating every error passing through the handler with the function name and file line of the stack trace's top frame (if one is found).

Maps are printed in key-sorted order as of Go 1.12 See https://golang.org/doc/go1.12#fmt

Code:

logger := newLogurLogger()
handler := logurhandler.WithStackInfo(logurhandler.New(logger))

err := errors.New("error")

handler.Handle(err)

Output:

error
map[file:example_go1_12_test.go:17 func:ExampleWithStackInfo]

func (*Handler) Handle Uses

func (h *Handler) Handle(err error)

Handle records an error event and forwards it to the underlying logger.

Code:

logger := newLogurLogger()
handler := logurhandler.New(logger)

err := errors.New("error")

handler.Handle(err)

Output:

error

Package logur imports 4 packages (graph) and is imported by 3 packages. Updated 2019-08-28. Refresh now. Tools for package owners.