log

package module
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Sep 9, 2025 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Middleware

func Middleware(opts ...Option) func(next http.Handler) http.Handler

Types

type Logger

type Logger struct {
	Skipper  func(r *http.Request) bool
	PreFunc  func(r *http.Request) *http.Request
	PostFunc func(r *http.Request, v *Response)
}

Logger is a middleware that logs HTTP requests and additional information to context.

func New

func New(opts ...Option) *Logger

func (*Logger) Middleware

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

type Option

type Option func(*option)

func WithLogger added in v0.1.5

func WithLogger(l Logger) Option

WithLogger sets a custom Logger directly.

func WithPostFunc added in v0.1.5

func WithPostFunc(f func(r *http.Request, v *Response)) Option

WithPostFunc sets a function which is called after the request is processed.

  • This will override the default PostFunc which logs some useful information.

func WithPreFunc added in v0.1.5

func WithPreFunc(f func(r *http.Request) *http.Request) Option

WithPreFunc sets a function which is called before the request is processed.

  • This will override the default PreFunc which adds some useful information to the context.

func WithSkipper added in v0.1.5

func WithSkipper(skipper func(r *http.Request) bool) Option

WithSkipper sets a function to skip middleware.

  • Default is nil.

type Response added in v0.1.5

type Response struct {
	// StartTime is time recorded before next middleware/handler is executed.
	StartTime time.Time
	// Latency is duration it took to execute rest of the handler chain (next(c) call).
	Latency time.Duration
	// Status is response status code. Then handler returns an echo.HTTPError then code from there.
	Status int
	// ResponseSize is response content length value. Note: when used with Gzip middleware this value may not be always correct.
	ResponseSize int64
}

Response contains extracted values from logger.

Jump to

Keyboard shortcuts

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