Skip to content

Commit 78a9069

Browse files
committed
fix: add return to example, clarify SetDefault in wrapping pattern
1 parent 6da8028 commit 78a9069

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

howto/Log.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ func (s *svc) HandleOrder(ctx context.Context, req *proto.OrderRequest) (*proto.
2626
slog.String("order_id", req.GetOrderId()),
2727
slog.Int("items", len(req.GetItems())),
2828
)
29-
// ...
29+
// ... business logic ...
30+
return &proto.OrderResponse{}, nil
3031
}
3132
```
3233

@@ -115,6 +116,10 @@ func init() {
115116
// Wrap with any slog.Handler middleware — e.g., slog-sampling, slog-dedup, etc.
116117
// NewSamplingHandler is a placeholder for your chosen middleware.
117118
sampled := NewSamplingHandler(cbHandler, 0.1)
119+
120+
// Use log.SetDefault for ColdBrew's handler so log.GetHandler()/log.SetLevel() work,
121+
// then override slog.SetDefault with the wrapped version for native slog calls.
122+
log.SetDefault(cbHandler)
118123
slog.SetDefault(slog.New(sampled))
119124
}
120125
```

0 commit comments

Comments
 (0)