Skip to content

Home > @opengovsg/logging > Logger > setBindings

Logger.setBindings() method ​

Bind the acting user at the **root level** (user_id) **in place** (mutates), so it persists for the rest of this logger's lifecycle - every subsequent line, audit and routine, attributes the actor. The mutating twin of Logger.withBindings(), for the common case where one request logger is threaded by reference and gains its identity mid-request.

⚠️ Mutation is shared: see the caveat on Logger.setAction(). Here the stakes are higher - if a logger is reused across requests (e.g. a module-level singleton), a bound user_id bleeds into other users' lines, **misattributing audit events**. Only ever call this on a per-request logger.

Signature:

typescript
setBindings(bindings: {
        userId?: string;
    }): Logger;

Parameters ​

ParameterTypeDescription
bindings{ userId?: string; }Root-level identity learned after creation.

Returns:

Logger

The same logger instance, for chaining.