logger

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Jan 29, 2021 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultLogger defaultLogger

DefaultLogger represents everywhere available logger with default LogSink. It is also used with package logger.Event(...) method executions.

View Source
var LogSink io.Writer

LogSink points to the writer that store all logs, default one is os.Stdout If you want to have it different, just set it prior using any `logger.New*(...)` function

Functions

func LogErrorWithBody

func LogErrorWithBody(ctx context.Context, err error, errName, responseBody string)

LogErrorWithBody updates logging context with details of the error and responseBody payload. This is later dumped with the request_finished event

func NewKievRequestLogger

func NewKievRequestLogger(appName string) func(http.HandlerFunc) http.HandlerFunc

NewKievRequestLogger creates a middleware that can wrap `http.HandlerFunc` of your server with logger inside of the `request.Context()`.

Types

type Context added in v0.1.0

type Context = zerolog.Context

Context is a type-alias for zerolog.Context

type Level added in v0.1.0

type Level = zerolog.Level

Level is a type-alias for zerolog.Level

type LoggedEvent added in v0.1.0

type LoggedEvent = zerolog.Event

LoggedEvent is a type-alias for zerolog.Event

func Error added in v0.2.0

func Error(name string, err error) *LoggedEvent

Event package function logs message with DefaultLogger on loglevel error

func Event

func Event(name string) *LoggedEvent

Event package function logs message with DefaultLogger

type Logger added in v0.1.0

type Logger interface {
	WithScope(map[string]interface{})
	IsDisabled() bool
	// contains filtered or unexported methods
}

Logger is an interface for the returned logger instance

func Get

func Get(ctx context.Context) Logger

Get returns Logger instance from the argument representing current `context.Context`. Useful to get the logger instance downstream somewhere deep in your app. Then you pass just the context instance all way down and get the `Logger` out using this function.

func New added in v0.1.0

func New(ctx context.Context, appName string) (Logger, context.Context)

New creates a logger with appName specified and attaches it to the provided ctx and the enriched context is returned as second value. If already logger exists in the context it returns it as it is.

func NewLambdaLogger added in v0.1.0

func NewLambdaLogger(ctx context.Context) (Logger, context.Context)

NewLambdaLogger returns a logger and enhanced context which is ready to log details of request in JSON responses compatible with Kiev format.

func NewRequestLogger

func NewRequestLogger(appName string, req *http.Request) (Logger, context.Context)

NewRequestLogger registers logger on the request and it's context and loads the logger scope from the request context.

func NewStandalone added in v0.1.0

func NewStandalone(appName string) (Logger, context.Context)

NewStandalone creates a logger with appName in fresh Context( `context.Background()` ) return as 2nd value

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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