logging

package
v0.0.0-...-0fe9a67 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2021 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ToContext

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

ToContext injects a logger into the context. It should be use in a pair with `FromContext` that extracts logger back.

Types

type Logger

type Logger interface {
	// WithString adds `val` of `string` type to the logging context and returns it to the caller.
	WithString(key, val string) Logger
	// WithInt64 adds `val` of `int64` type to the logging context and returns it to the caller.
	WithInt64(key string, val int64) Logger
	// WithInt adds `val` of `int` type to the logging context and returns it to the caller.
	WithInt(key string, val int) Logger
	// WithError adds `err` to the logging context and returns it to the caller.
	WithError(err error) Logger
	// Debug flushes logging context with "debug" severity level.
	Debug(msg string)
	// Info flushes logging context with "info" severity level.
	Info(msg string)
	// Error flushes logging context with "error" severity level.
	Error(msg string)
	// IsDebug reports if logging level severity is higher than 'debug' level.
	IsDebug() bool
}

Logger is an abstraction used for logging in the service.

func FromContext

func FromContext(ctx context.Context) Logger

FromContext extracts logger from the context. It will panic if context has no associated logger in it. It should be use in a pair with `ToContext` that injects logger into context.

type TestLogger

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

TestLogger should be used only for testing purposes.

func NewTestLogger

func NewTestLogger() *TestLogger

func (*TestLogger) Debug

func (tl *TestLogger) Debug(msg string)

func (*TestLogger) Entries

func (tl *TestLogger) Entries() []map[string]interface{}

func (*TestLogger) Error

func (tl *TestLogger) Error(msg string)

func (*TestLogger) Info

func (tl *TestLogger) Info(msg string)

func (*TestLogger) IsDebug

func (tl *TestLogger) IsDebug() bool

func (*TestLogger) WithError

func (tl *TestLogger) WithError(err error) Logger

func (*TestLogger) WithInt

func (tl *TestLogger) WithInt(key string, val int) Logger

func (*TestLogger) WithInt64

func (tl *TestLogger) WithInt64(key string, val int64) Logger

func (*TestLogger) WithString

func (tl *TestLogger) WithString(key, val string) Logger

type ZapWrapper

type ZapWrapper struct {
	*zap.Logger
}

ZapWrapper is an adapter between service defined logging interface and zap logging implementation.

func NewZapLogger

func NewZapLogger(lvl string) ZapWrapper

NewZapLogger returns a zap logger adapter to be used with `Logging` interface.

func (ZapWrapper) Debug

func (zw ZapWrapper) Debug(msg string)

func (ZapWrapper) Error

func (zw ZapWrapper) Error(msg string)

func (ZapWrapper) Info

func (zw ZapWrapper) Info(msg string)

func (ZapWrapper) IsDebug

func (zw ZapWrapper) IsDebug() bool

func (ZapWrapper) WithError

func (zw ZapWrapper) WithError(err error) Logger

func (ZapWrapper) WithInt

func (zw ZapWrapper) WithInt(key string, val int) Logger

func (ZapWrapper) WithInt64

func (zw ZapWrapper) WithInt64(key string, val int64) Logger

func (ZapWrapper) WithString

func (zw ZapWrapper) WithString(key, val string) Logger

func (ZapWrapper) WithUint64

func (zw ZapWrapper) WithUint64(key string, val uint64) Logger

Jump to

Keyboard shortcuts

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