chizap

package module
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2023 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package chizap provides a logging and recovery middleware for chi using zap.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Get

func Get(r *http.Request) *zap.Logger

Get returns the *zap.Logger instance saved in the request context by the Logger middleware.

Must be called after the Logger middleware.

func GetSugared

func GetSugared(r *http.Request) *zap.SugaredLogger

GetSugared is shorthand for:

Get(r).Sugar()

func Logger

func Logger(l *zap.Logger, excludedPaths ...string) func(http.Handler) http.Handler

Logger returns a middleware handler that logs all requests using the passed zap.Logger.

Additionally, it saves a logger instance in the request context, to be retrieved using Get. Besides the fields already added to the logger, that instance also holds the following fields:

  • request_id: the request ID, if set by github.com/go-chi/chi/v5/middleware.RequestID
  • proto: the request protocol
  • method: the HTTP method of the request
  • path: the path of the request
  • query: the query string of the request
  • remote: the remote address of the client
  • user_agent: the user agent of the client
  • referer: the referer of the client

If you don't want a certain path prefix to be logged, you may specify it as one of the excludedPaths. Even if a path prefix is echoed, the logger will still be saved in the request context.

func Recoverer

func Recoverer(next http.Handler) http.Handler

Recoverer recovers from panics and logs the stack trace using the logger added by Logger.

Types

This section is empty.

Jump to

Keyboard shortcuts

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