diff --git a/docs/api/logger-bind.md b/docs/api/logger-bind.md index cb04652..b3a6ed4 100644 --- a/docs/api/logger-bind.md +++ b/docs/api/logger-bind.md @@ -28,15 +28,18 @@ pub fn[S] Logger::bind(self : Logger[S], fields : Array[Field]) -> Logger[Contex #### output -- `Logger[ContextSink[S]]` - New logger wrapper that prepends shared fields at write time. +- `Logger[ContextSink[S]]` - New logger value whose visible sink type becomes `ContextSink[S]` and prepends shared fields at write time. ### Explanation Detailed rules explaining key parameters and behaviors -- `bind(...)` delegates directly to `with_context_fields(...)`. -- The original logger value is not mutated; a wrapped logger is returned. +- `bind(...)` delegates directly to `with_context_fields(...)`; it is an alias, not a different implementation. +- The original logger value is not mutated; a derived wrapped logger is returned. +- The returned logger changes visible type from `Logger[S]` to `Logger[ContextSink[S]]` because the sink pipeline is extended with stored shared fields. +- Stored target, minimum level, and timestamp behavior are preserved while the sink pipeline changes. - Shared fields are applied to every later log call emitted through the returned logger. +- When a log call also passes per-record fields, the shared bound fields are prepended before those per-call fields because `bind(...)` inherits the same merge order as `with_context_fields(...)`. - This alias is useful when you prefer shorter chaining syntax in application code. ### How to Use @@ -64,6 +67,8 @@ let worker = Logger::new(console_sink(), target="app") In this example, `bind(...)` communicates intent without changing underlying behavior. +And the returned logger still keeps the same target and level-gating behavior as the source logger. + ### Error Case e.g.: @@ -77,3 +82,5 @@ e.g.: 2. This alias exists for ergonomics, not for different semantics. +3. Use `with_context_fields(...)` when the longer name makes the sink-type change to `ContextSink[S]` clearer at the call site. +