@@ -19,8 +19,8 @@ type router struct {
1919// Example usage:
2020//
2121// r := slogmulti.Router().
22- // Add(consoleHandler, slogmulti.Level (slog.LevelInfo)).
23- // Add(fileHandler, slogmulti.Level (slog.LevelError)).
22+ // Add(consoleHandler, slogmulti.LevelIs (slog.LevelInfo)).
23+ // Add(fileHandler, slogmulti.LevelIs (slog.LevelError)).
2424// Handler()
2525//
2626// Returns:
@@ -32,26 +32,26 @@ func Router() *router {
3232 }
3333}
3434
35- // Add registers a new handler with optional matchers to the router.
36- // The handler will only process records if all provided matchers return true.
35+ // Add registers a new handler with optional predicates to the router.
36+ // The handler will only process records if all provided predicates return true.
3737//
3838// Args:
3939//
4040// handler: The slog.Handler to register
41- // matchers : Optional functions that determine if a record should be routed to this handler
41+ // predicates : Optional functions that determine if a record should be routed to this handler
4242//
4343// Returns:
4444//
4545// The router instance for method chaining
46- func (h * router ) Add (handler slog.Handler , matchers ... func (ctx context.Context , r slog.Record ) bool ) * router {
46+ func (h * router ) Add (handler slog.Handler , predicates ... func (ctx context.Context , r slog.Record ) bool ) * router {
4747 return & router {
4848 handlers : append (
4949 h .handlers ,
5050 & RoutableHandler {
51- matchers : matchers ,
52- handler : handler ,
53- groups : []string {},
54- attrs : []slog.Attr {},
51+ predicates : predicates ,
52+ handler : handler ,
53+ groups : []string {},
54+ attrs : []slog.Attr {},
5555 },
5656 ),
5757 }
@@ -72,13 +72,13 @@ func (h *router) Handler() slog.Handler {
7272var _ slog.Handler = (* RoutableHandler )(nil )
7373
7474// RoutableHandler wraps a slog.Handler with conditional matching logic.
75- // It only forwards records to the underlying handler if all matchers return true.
75+ // It only forwards records to the underlying handler if all predicates return true.
7676// This enables sophisticated routing scenarios like level-based or attribute-based routing.
7777//
7878// @TODO: implement round robin strategy for load balancing across multiple handlers
7979type RoutableHandler struct {
80- // matchers contains functions that determine if a record should be processed
81- matchers []func (ctx context.Context , r slog.Record ) bool
80+ // predicates contains functions that determine if a record should be processed
81+ predicates []func (ctx context.Context , r slog.Record ) bool
8282 // handler is the underlying slog.Handler that processes matching records
8383 handler slog.Handler
8484 // groups tracks the current group hierarchy for proper attribute handling
@@ -102,7 +102,7 @@ func (h *RoutableHandler) Enabled(ctx context.Context, l slog.Level) bool {
102102 return h .handler .Enabled (ctx , l )
103103}
104104
105- // Handle processes a log record if all matchers return true.
105+ // Handle processes a log record if all predicates return true.
106106// This method implements the slog.Handler interface requirement.
107107//
108108// Args:
@@ -119,8 +119,8 @@ func (h *RoutableHandler) Handle(ctx context.Context, r slog.Record) error {
119119 slogcommon .AppendRecordAttrsToAttrs (h .attrs , h .groups , & r )... ,
120120 )
121121
122- for _ , matcher := range h .matchers {
123- if ! matcher (ctx , clone ) {
122+ for _ , predicate := range h .predicates {
123+ if ! predicate (ctx , clone ) {
124124 return nil
125125 }
126126 }
@@ -143,10 +143,10 @@ func (h *RoutableHandler) Handle(ctx context.Context, r slog.Record) error {
143143// A new RoutableHandler with the additional attributes
144144func (h * RoutableHandler ) WithAttrs (attrs []slog.Attr ) slog.Handler {
145145 return & RoutableHandler {
146- matchers : h .matchers ,
147- handler : h .handler .WithAttrs (attrs ),
148- groups : slices .Clone (h .groups ),
149- attrs : slogcommon .AppendAttrsToGroup (h .groups , h .attrs , attrs ... ),
146+ predicates : h .predicates ,
147+ handler : h .handler .WithAttrs (attrs ),
148+ groups : slices .Clone (h .groups ),
149+ attrs : slogcommon .AppendAttrsToGroup (h .groups , h .attrs , attrs ... ),
150150 }
151151}
152152
@@ -171,9 +171,9 @@ func (h *RoutableHandler) WithGroup(name string) slog.Handler {
171171 }
172172
173173 return & RoutableHandler {
174- matchers : h .matchers ,
175- handler : h .handler .WithGroup (name ),
176- groups : append (slices .Clone (h .groups ), name ),
177- attrs : h .attrs ,
174+ predicates : h .predicates ,
175+ handler : h .handler .WithGroup (name ),
176+ groups : append (slices .Clone (h .groups ), name ),
177+ attrs : h .attrs ,
178178 }
179179}
0 commit comments