ctxerror

package
v1.2.7 Latest Latest
Warning

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

Go to latest
Published: May 8, 2020 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package ctxerror provides a context-aware error facility.

Inspired by log15-style (semi-)structured logging, it also provides a log15 bridge.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Crit

func Crit(l log.Logger, e error, msg string, ctx ...interface{})

Crit logs an error with a message prefix using a log15-style logger.

func Debug

func Debug(l log.Logger, e error, msg string, ctx ...interface{})

Debug logs an error with a message prefix using a log15-style logger.

func Error

func Error(l log.Logger, e error, msg string, ctx ...interface{})

Error logs an error with a message prefix using a log15-style logger.

func Info

func Info(l log.Logger, e error, msg string, ctx ...interface{})

Info logs an error with a message prefix using a log15-style logger.

func Log15

func Log15(f Log15Func, e error)

Log15 logs an error with a log15-style logging function. It handles both regular errors and Log15Logger-compliant errors.

func Log15WithMsg

func Log15WithMsg(f Log15Func, e error, msg string, ctx ...interface{})

Log15WithMsg logs an error with a message prefix using a log15-style logging function. It is a shortcut for a common pattern of prepending a context prefix.

func Trace

func Trace(l log.Logger, e error, msg string, ctx ...interface{})

Trace logs an error with a message prefix using a log15-style logger.

func Warn

func Warn(l log.Logger, e error, msg string, ctx ...interface{})

Warn logs an error with a message prefix using a log15-style logger.

Types

type CtxError

type CtxError interface {
	// Error returns a fully formatted message, with context info.
	Error() string

	// Message returns the bare error message, without context info.
	Message() string

	// Contexts returns message contexts.
	// Caller shall not modify the returned map.
	Contexts() map[string]interface{}

	// WithCause chains an error after the receiver.
	// It returns the merged/chained instance,
	// where the message is "<receiver.Message>: <c.Message>",
	// and with contexts merged (ones in c takes precedence).
	WithCause(c error) CtxError
}

CtxError is a context-aware error container.

func New

func New(msg string, ctx ...interface{}) CtxError

New creates and returns a new context-aware error.

type Log15Func

type Log15Func func(msg string, ctx ...interface{})

Log15Func is a log15-compatible logging function.

type Log15Logger

type Log15Logger interface {
	Log15(f Log15Func)
}

Log15Logger logs something with a log15-style logging function.

Directories

Path Synopsis
Package mock_ctxerror is a generated GoMock package.
Package mock_ctxerror is a generated GoMock package.

Jump to

Keyboard shortcuts

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