-
-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathmiddleware.go
More file actions
28 lines (26 loc) · 843 Bytes
/
middleware.go
File metadata and controls
28 lines (26 loc) · 843 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
package slogmulti
import (
"log/slog"
)
// Middleware is a function type that transforms one slog.Handler into another.
// It follows the standard middleware pattern where a function takes a handler
// and returns a new handler that wraps the original with additional functionality.
//
// Middleware functions can be used to:
// - Transform log records (e.g., add timestamps, modify levels)
// - Filter records based on conditions
// - Add context or attributes to records
// - Implement cross-cutting concerns like error recovery or sampling
//
// Example usage:
//
// gdprMiddleware := NewGDPRMiddleware()
// sink := slog.NewJSONHandler(os.Stderr, &slog.HandlerOptions{})
//
// logger := slog.New(
// slogmulti.
// Pipe(gdprMiddleware).
// // ...
// Handler(sink),
// )
type Middleware func(slog.Handler) slog.Handler