nlogger

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2019 License: MIT Imports: 9 Imported by: 18

Documentation

Index

Constants

View Source
const LoggerKey loggerKey = "nlogger.Structured"

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 Structured) context.Context

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

Types

type Basic added in v0.1.0

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

Basic logger interface provides a very basic logger with functions that prints messages corresponding to the log level picked

type Entry added in v0.1.0

type Entry interface {
	String(key string, value string)
	Int(key string, value int)
	Int64(key string, value int64)
	Float(key string, value float64)
	Bool(key string, value bool)
	Err(key string, value error)
	ObjectFunc(key string, value EntryFunc)
}

Entry represents a single log line and is what you use in the *WithFields callback. You would call any of the functions in the interface to add a keyed value to the log line.

type EntryFunc added in v0.1.0

type EntryFunc func(Entry)

EntryFunc defines the callback that you implement when using the *WithFields function

type Logger

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

Logger is a generic Logger interface

type Provider added in v0.0.4

type Provider interface {
	// Get returns the Provider's attached logger in a thread safe manner
	Get() Structured
	// Replace replaces the provider's internal logger in a thread safe manner
	Replace(Structured)
}

Provider is an interface to get a thread safe logger provider with the ability to replace the internal logger provided

func NewProvider added in v0.0.4

func NewProvider(l Structured) Provider

NewProvider returns a new Structured Provider from the given Logger l

type Structured added in v0.1.0

type Structured interface {
	Debug(string)
	DebugWithFields(string, EntryFunc)
	Info(string)
	InfoWithFields(string, EntryFunc)
	Warn(string)
	WarnWithFields(string, EntryFunc)
	Error(string)
	ErrorWithFields(string, EntryFunc)
	Fatal(string)
	FatalWithFields(string, EntryFunc)
}

Structured is a generic structured logger that allows you to add fields to log messages

func FromContext

func FromContext(ctx context.Context) Structured

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

func MustFromContext

func MustFromContext(ctx context.Context) Structured

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

New will return a default logger instance

func NewWithLog added in v0.2.0

func NewWithLog(log *log.Logger) Structured

NewWithLog allows you to pass in a log.Logger which then gets snuggly wrapped in an interface that suits the nlogger.Structured interface.

func ToStructured added in v0.1.0

func ToStructured(logger Basic) Structured

ToStructured lets you use a simple logger that conforms to the Basic interface to satisfy the needs of packages that use the Structured logger

Jump to

Keyboard shortcuts

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