logrusmiddleware

package module
v0.0.0-...-c7f2fd7 Latest Latest
Warning

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

Go to latest
Published: Jun 19, 2018 License: MIT Imports: 6 Imported by: 0

README

GoDoc

logrus-middleware

Simple logging middleware for Go using logrus

Note This needs a new maintainer. I no longer use this, so I'd be happy to transfer ownership if you find it useful. Open an issue or contact me if you are interested.

"Normal" net/http middleware for Go for logging.

See the example

Based on: https://github.com/meatballhat/negroni-logrus

Documentation

Overview

Package logrusmiddleware is a simple net/http middleware for logging using logrus

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Handler

type Handler struct {
	http.ResponseWriter
	// contains filtered or unexported fields
}

Handler is the actual middleware that handles logging

func (*Handler) Header

func (h *Handler) Header() http.Header

Header is a wrapper around ResponseWriter.Header

func (*Handler) Hijack

func (h *Handler) Hijack() (net.Conn, *bufio.ReadWriter, error)

Hijack implements http.Hijacker. It simply wraps the underlying ResponseWriter's Hijack method if there is one, or returns an error.

func (*Handler) ServeHTTP

func (h *Handler) ServeHTTP(rw http.ResponseWriter, r *http.Request)

ServeHTTP calls the "real" handler and logs using the logger

func (*Handler) Write

func (h *Handler) Write(b []byte) (int, error)

Write is a wrapper for the "real" ResponseWriter.Write

func (*Handler) WriteHeader

func (h *Handler) WriteHeader(s int)

WriteHeader is a wrapper around ResponseWriter.WriteHeader

type Middleware

type Middleware struct {
	// Logger is the log.Logger instance used to log messages with the Logger middleware
	Logger *logrus.Logger
	// Name is the name of the application as recorded in latency metrics
	Name string
}

Middleware is a middleware handler for HTTP logging

func (*Middleware) Handler

func (m *Middleware) Handler(h http.Handler, component string) *Handler

Handler create a new handler. component, if set, is emitted in the log messages.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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