zapctx

package module
v0.0.0-...-7b48312 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2020 License: Apache-2.0 Imports: 3 Imported by: 1

README

zapx

context wrapper for uber's zap library

Add logger to Context
parent := context.Background()
ctx := zapctx.NewContext(parent, logger)
Retrieve logger from Context
logger := zapctx.FromContext(ctx)
logger.Info("blah")

or used directly

zapctx.FromContext(ctx).Info("blah")

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FromContext

func FromContext(ctx context.Context) *zap.Logger

FromContext retrieves the logger from the given Context. If no logger was found, FromContext returns the nop logger

func InjectLogger

func InjectLogger(logger *zap.Logger) func(http.Handler) http.Handler

InjectLogger returns handler to inject logger into request context

func Middleware

func Middleware(opts ...Option) func(h http.Handler) http.Handler

Middleware provides web middleware to inject a logger into the request context

func NewContext

func NewContext(parent context.Context, logger *zap.Logger) context.Context

NewContext returns a new context with the given logger attached

Types

type Option

type Option func(*options)

Option provides a functional

func WithFactory

func WithFactory(fn func(req *http.Request) *zap.Logger) Option

WithFactory allows a custom logger to be returned

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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