nlogger

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Jan 29, 2019 License: MIT Imports: 4 Imported by: 19

Documentation

Index

Constants

View Source
const LoggerKey loggerKey = "logger"

LoggerKey is the key to access the logger in context

Variables

View Source
var ErrLoggerNotFoundInContext = errors.New("Logger not found in context")

ErrLoggerNotFoundInContext is the error when calling MustFromContext and the logger is not found

Functions

func SetInContext

func SetInContext(ctx context.Context, logger Logger) context.Context

SetInContext sets the logger in a context and returns the new context

Types

type Logger

type Logger interface {
	Debug(string)
	Info(string)
	Warn(string)
	Error(string)
	Fatal(string)
}

Logger is a generic Logger interface

func FromContext

func FromContext(ctx context.Context) Logger

FromContext gets the logger from context. If context does not exist, it returns nil.

func MustFromContext

func MustFromContext(ctx context.Context) Logger

MustFromContext gets the logger from context. If context does not exist, it panics with a ErrLoggerNotFoundInContext.

func New

func New(target io.Writer, prefix string) Logger

New will return a default logger instance

Jump to

Keyboard shortcuts

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