Documentation ¶
Overview ¶
Package logrus is a simple net/http middleware for logging
Index ¶
- func DefaultAfter(entry *logrus.Entry, rw ResponseWrapper, latency time.Duration, name string) *logrus.Entry
- func DefaultBefore(entry *logrus.Entry, req *http.Request, remoteAddr string) *logrus.Entry
- func New() func(http.Handler) http.Handler
- func NewLogger(logger *logrus.Logger, name string) func(http.Handler) http.Handler
- type AfterFunc
- type BeforeFunc
- type Middleware
- type ResponseWrapper
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DefaultAfter ¶
func DefaultAfter(entry *logrus.Entry, rw ResponseWrapper, latency time.Duration, name string) *logrus.Entry
DefaultAfter is the default func assigned to *Middleware.After
func DefaultBefore ¶
DefaultBefore is the default func assigned to *Middleware.Before
Types ¶
type AfterFunc ¶
AfterFunc is the func type used to modify or replace the *logrus.Entry after calling the next func in the middleware chain
type BeforeFunc ¶
BeforeFunc is the func type used to modify or replace the *logrus.Entry 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 *logrus.Logger // Name is the name of the application as recorded in latency metrics Name string Before func(*logrus.Entry, *http.Request, string) *logrus.Entry After func(*logrus.Entry, ResponseWrapper, time.Duration, string) *logrus.Entry // 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 (*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(w http.ResponseWriter, r *http.Request)
ServeHTTP calls the "real" handler and logs using the logger
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
type ResponseWrapper ¶
type ResponseWrapper struct { http.ResponseWriter // contains filtered or unexported fields }
ResponseWrapper wrapper to capture status.
func (*ResponseWrapper) Write ¶
func (w *ResponseWrapper) Write(b []byte) (int, error)
Write capture written bytes.
func (*ResponseWrapper) WriteHeader ¶
func (w *ResponseWrapper) WriteHeader(code int)
WriteHeader capture status.