logrus

package module
v0.0.0-...-9ed4dd3 Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2019 License: Apache-2.0 Imports: 5 Imported by: 0

README

Logrus Middleware

A simple logrus liddleware with a dynamique log level base on the http response status. Also available for negroni

Documentation

Index

Constants

View Source
const EntryKey key = 0

EntryKey is the context key for the logrus.Entry.

It use a private struct in order to avoid any conflict with other packages. Its value of zero is arbitrary.

Variables

This section is empty.

Functions

func LogError

func LogError(ctx context.Context, err error)

LogError add an error into the context.

This error will be added as a field inside the request log.

Types

type Middleware

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

Middleware used to log the requests with a level based on the HTTP response status.

It is also possible to add an error with the LogError method with the request context.

The levels are: - 2XX => INFO - 3XX / 4XX => WARNING - 5XX => ERROR

func NewMiddleware

func NewMiddleware(level string, options ...Option) *Middleware

NewMiddleware instantiate a new Middleware.

func (*Middleware) ServeHTTP

func (t *Middleware) ServeHTTP(w http.ResponseWriter, r *http.Request, next http.HandlerFunc)

ServeHTTP serve the request then call the next middleware.

func (*Middleware) Wrap

func (t *Middleware) Wrap(handler http.HandlerFunc) http.Handler

Wrap a classic http handler.

type Option

type Option = func(*logrus.Logger)

Option is a function modifying the logger and used as option.

func WithFormatter

func WithFormatter(formatter logrus.Formatter) Option

WithFormatter update the logger format.

Jump to

Keyboard shortcuts

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