logrus

package
v1.0.6 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2021 License: BSD-2-Clause Imports: 7 Imported by: 3

Documentation

Overview

Package logrus is a logrus(https://godoc.org/github.com/Sirupsen/logrus) net/http middleware to log information about http handler. It can output both in text and JSON format. Both output format can be completely customized.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type LogResponseWriter

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

LogResponseWriter is a custom type that extends http.ResponseWriter interface to capture and provide an easy access to http status code

func (*LogResponseWriter) Header

func (w *LogResponseWriter) Header() http.Header

Header returns the header to satisfy the http.ResponseWriter interface

func (*LogResponseWriter) Size

func (w *LogResponseWriter) Size() int

Size provides the size of response object

func (*LogResponseWriter) Status

func (w *LogResponseWriter) Status() int

Status is a easy way to retrieve the status code

func (*LogResponseWriter) Write

func (w *LogResponseWriter) Write(data []byte) (int, error)

Write capture the size of the data written and satisfy the http.ResponseWriter interface

func (*LogResponseWriter) WriteHeader

func (w *LogResponseWriter) WriteHeader(code int)

WriteHeader capture the status code and satisfies the http.ResponseWriter interface

type Logger

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

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

func NewCustomMiddleware

func NewCustomMiddleware(level logrus.Level, formatter logrus.Formatter, name string) *Logger

NewCustomMiddleware builds a *Logger with the given level and formatter

func NewFileLogger

func NewFileLogger(w io.Writer) *Logger

NewFileLogger writes to a file

func NewJSONFileLogger

func NewJSONFileLogger(w io.Writer) *Logger

NewJSONFileLogger writes to a file in JSON format

func NewJSONLogger

func NewJSONLogger() *Logger

NewJSONLogger returns a new *Logger that logs in JSON format

func NewLogger

func NewLogger() *Logger

NewLogger returns a new *Logger

func NewMiddlewareFromLogger

func NewMiddlewareFromLogger(logger *logrus.Logger, name string) *Logger

NewMiddlewareFromLogger returns a new *Logger which writes to a given logrus logger.

func (*Logger) Middleware

func (l *Logger) Middleware(h http.Handler) http.Handler

Middleware works with http.Handler type

func (*Logger) MiddlewareFn

func (l *Logger) MiddlewareFn(fn http.HandlerFunc) http.HandlerFunc

MiddlewareFn works with http.HandlerFunc type

Jump to

Keyboard shortcuts

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