access_log

package
v0.0.0-...-e49ca0b Latest Latest
Warning

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

Go to latest
Published: Feb 8, 2025 License: MPL-2.0 Imports: 7 Imported by: 0

README

Access Logging Middleware

The access logging middleware logs each request with the following information:

  • correlationID
  • client address
  • HTTP method
  • path

Example

The access logging will use the default logger slog.Default() and INFO log level.

finalHandler := midgard.StackMiddlewareHandler(
    []midgard.Middleware{
        access_log.New(),
    },
    http.HandlerFunc(HelloHandler),
)

It can also be configured with a custom logger and level.

finalHandler := midgard.StackMiddlewareHandler(
    []midgard.Middleware{
        access_log.New(
            access_log.WithLogger(someOtherLogger),
            access_log.WithLogLevel(slog.LevelDebug),
        ),
    },
    http.HandlerFunc(HelloHandler),
)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(options ...func(*Handler) error) (defs.Middleware, error)

New generates a new access logging middleware.

func WithLogLevel

func WithLogLevel(level slog.Level) func(h *Handler) error

WithLogLevel configures the log level to use with the logger.

func WithLogger

func WithLogger(log *slog.Logger) func(h *Handler) error

WithLogger configures the logger to use.

Types

type Handler

type Handler struct {
	defs.MWBase
}

Handler holds the information necessary for the log

func (*Handler) GetMWBase

func (h *Handler) GetMWBase() *defs.MWBase

func (*Handler) ServeHTTP

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

accessLogging is the access logging middleware. It logs every request with its correlationID, the clients address, http method and accessed path.

Jump to

Keyboard shortcuts

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