negronizerolog

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Mar 7, 2022 License: MIT Imports: 7 Imported by: 0

README

negroni-zerolog

PkgGoDev Main Workflow Status

Adaptation of meatballhat/negroni-logrus.

logrus middleware for negroni

Usage

Create a new middleware with NewMiddleware

If you want to reuse an already initialized zerolog.Logger, you should be using NewMiddlewareFromLogger

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultAfter

func DefaultAfter(entry zerolog.Logger, res negroni.ResponseWriter, latency time.Duration, name string) zerolog.Logger

DefaultAfter is the default func assigned to *Middleware.After

func DefaultBefore

func DefaultBefore(entry zerolog.Logger, req *http.Request, remoteAddr string) zerolog.Logger

DefaultBefore is the default func assigned to *Middleware.Before

Types

type AfterFunc

AfterFunc is the func type used to modify or replace the zerolog.Logger after calling the next func in the middleware chain

type BeforeFunc

type BeforeFunc func(zerolog.Logger, *http.Request, string) zerolog.Logger

BeforeFunc is the func type used to modify or replace the zerolog.Logger prior to calling the next func in the middleware chain

type Middleware

type Middleware struct {
	// Logger is the log.Logger instance used to log messages with the Logger middleware
	Logger zerolog.Logger
	// Name is the name of the application as recorded in latency metrics
	Name   string
	Before func(zerolog.Logger, *http.Request, string) zerolog.Logger
	After  func(zerolog.Logger, negroni.ResponseWriter, time.Duration, string) zerolog.Logger
	// contains filtered or unexported fields
}

Middleware is a middleware handler that logs the request as it goes in and the response as it goes out.

func NewCustomMiddleware

func NewCustomMiddleware(level zerolog.Level, name string) *Middleware

NewCustomMiddleware builds a *Middleware with the given level

func NewMiddleware

func NewMiddleware() *Middleware

NewMiddleware returns a new *Middleware, yay!

func NewMiddlewareFromLogger

func NewMiddlewareFromLogger(logger zerolog.Logger, name string) *Middleware

NewMiddlewareFromLogger returns a new *Middleware which writes to a given zerolog logger.

func (*Middleware) ExcludeURL

func (m *Middleware) ExcludeURL(u string) error

ExcludeURL adds a new URL u to be ignored during logging. The URL u is parsed, hence the returned error

func (*Middleware) ExcludedURLs

func (m *Middleware) ExcludedURLs() []string

ExcludedURLs returns the list of excluded URLs for this middleware

func (*Middleware) ServeHTTP

func (m *Middleware) ServeHTTP(rw http.ResponseWriter, r *http.Request, next http.HandlerFunc)

func (*Middleware) SetLogCompleted

func (m *Middleware) SetLogCompleted(v bool)

SetLogCompleted accepts a bool to control the logging of "completed handling request" after returning from the next middleware

func (*Middleware) SetLogStarting

func (m *Middleware) SetLogStarting(v bool)

SetLogStarting accepts a bool to control the logging of "started handling request" prior to passing to the next middleware

Jump to

Keyboard shortcuts

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