fiberslog

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2023 License: MIT Imports: 4 Imported by: 0

README

fiberslog

Build Lint

fiberslog is a golang.org/x/exp/slog logging middleware for Fiber, a web framework for Go. This middleware logs incoming HTTP requests and outgoing HTTP responses, including their respective status code, timestamp and latency.

Installation

You can install the package via Go modules:

go get github.com/hallabro-consulting-ab/fiberslog

Usage

import "github.com/hallabro-consulting-ab/fiberslog"

app := fiber.New()
app.Use(fiberslog.New(options...))

Where options is a list of fiberslog.Option functions. The following options are available:

  • fiberslog.WithLogger(logger *slog.Logger) sets the logger to use.
  • fiberslog.WithPopulateContext(populate bool) sets whether to populate the request context with the logger. With this option set you can access the logger by calling logger := ctx.Locals("logger").
  • fiberslog.WithNext(next func(ctx *fiber.Ctx) bool) sets the next handler to call. This is useful if you want to skip the middleware for whatever reason.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(options ...Option) fiber.Handler

Types

type Config

type Config struct {
	Next            func(ctx *fiber.Ctx) bool
	Logger          *slog.Logger
	PopulateContext bool
}

type Option

type Option func(*Config)

func WithLogger

func WithLogger(logger *slog.Logger) Option

func WithNext

func WithNext(next func(ctx *fiber.Ctx) bool) Option

func WithPopulateContext

func WithPopulateContext(populate bool) Option

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳