bunrouterslog

package module
v0.0.0-...-9b1aeb1 Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2024 License: MIT Imports: 11 Imported by: 0

README

bunrouter slog

Bunrouter Middleware

This is a bunrouter middleware that adds a slog logger to the context, and logs some key details about the request and response. It also adds a RequestID to the context, and logs it with each request.

See the middleware example

Slog -> Otel Event Handler

This is a bunrouter slog handler that sends logs to OpenTelemetry as events.

See the otel example

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ContextWithLogger

func ContextWithLogger(ctx context.Context, logger *slog.Logger) context.Context

func ContextWithRequestID

func ContextWithRequestID(ctx context.Context, id RequestID) context.Context

func FlyInfoDetector

func FlyInfoDetector(request bunrouter.Request) ([]any, error)

func LoggerFromContext

func LoggerFromContext(ctx context.Context) *slog.Logger

func NewBunrouterMiddleware

func NewBunrouterMiddleware(options ...Option) bunrouter.MiddlewareFunc

func NewOtelEventHandler

func NewOtelEventHandler(ctx context.Context, inner slog.Handler) slog.Handler

func StandardInfoDector

func StandardInfoDector(request bunrouter.Request) ([]any, error)

Types

type Option

type Option func(m *bunrouterMiddleware)

func WithRequestDetectors

func WithRequestDetectors(detectors ...RequestDetector) Option

type RequestDetector

type RequestDetector func(request bunrouter.Request) ([]any, error)

type RequestID

type RequestID struct {
	typeid.TypeID[requestIdPrefix]
}

func MustNewRequestID

func MustNewRequestID() RequestID

func NewRequestID

func NewRequestID() (RequestID, error)

func RequestIDFromContext

func RequestIDFromContext(ctx context.Context) (RequestID, bool)

type ResponseInfo

type ResponseInfo struct {
	Status       string
	BytesWritten int
}

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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