MCPcopy Create free account
hub / github.com/riverqueue/river / NewMiddleware

Function NewMiddleware

riverlog/river_log.go:119–124  ·  view source on GitHub ↗

NewMiddleware initializes a new Middleware with the given slog handler initialization function and configuration. newHandler is a function which is invoked on every Work execution to generate a new slog.Handler for a work-specific slog.Logger. It should take an io.Writer and return a slog.Handler o

(newSlogHandler func(w io.Writer) slog.Handler, config *MiddlewareConfig)

Source from the content-addressed store, hash-verified

117// func (w *MyWorker) Work(ctx context.Context, job *river.Job[MyArgs]) error {
118// Logger(ctx).InfoContext(ctx, "Hello from work")
119func NewMiddleware(newSlogHandler func(w io.Writer) slog.Handler, config *MiddlewareConfig) *Middleware {
120 return &Middleware{
121 config: defaultConfig(config),
122 newSlogHandler: newSlogHandler,
123 }
124}
125
126// NewMiddlewareCustomContext initializes a new Middleware with the given arbitrary
127// context initialization function and configuration.

Callers 3

ExampleNewMiddlewareFunction · 0.92
TestMiddlewareFunction · 0.85

Calls 1

defaultConfigFunction · 0.85

Tested by 3

ExampleNewMiddlewareFunction · 0.74
TestMiddlewareFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…