Home > @opengovsg/logging > Logger > withBindings
Logger.withBindings() method
Return a **new** logger that binds the acting user at the **root level** (user_id), leaving the original unchanged. Unlike Logger.withContext() (which lands in context), user_id is a top-level field and so satisfies the audit scope-read asserts - e.g. binding the acting user once it is known mid-request (self-signup, deferred auth), so audit.resource.* and other actor-scoped events attribute the actor instead of warning. Request-fixed facets (client_ip, user_agent, path) are set at creation and inherited untouched.
Signature:
typescript
withBindings(bindings: {
userId?: string;
}): Logger;Parameters
| Parameter | Type | Description |
|---|---|---|
| bindings | { userId?: string; } | Root-level identity learned after creation. |
Returns:
A new Logger with user_id bound at the root.