Skip to content

fix(browser): implement setBindings on browser logger#2403

Open
mibragimov wants to merge 1 commit intopinojs:mainfrom
mibragimov:fix/issue-2021
Open

fix(browser): implement setBindings on browser logger#2403
mibragimov wants to merge 1 commit intopinojs:mainfrom
mibragimov:fix/issue-2021

Conversation

@mibragimov
Copy link

Summary

Implement setBindings for browser loggers so import { pino } from "pino" logger instances support the documented Logger API and do not throw at runtime.

Root Cause

setBindings exists in LoggerExtras typings (pino.d.ts) and is implemented for Node loggers via lib/proto.js, but browser runtime loggers created in browser.js did not define setBindings.

As a result, browser logger instances could throw:

TypeError: logger.setBindings is not a function

when using the named export path described in the issue.

Fix

  • Added logger.setBindings(bindings) to browser.js.
  • The implementation stores the new bindings and refreshes level methods so subsequent logs include updated bindings.
  • Added browser tests to verify:
    • setBindings applies bindings to logs.
    • calling setBindings again overwrites previous bindings.
    • setBindings is exposed as a function on browser logger instances.

Testing

  • npm run -s lint
  • node test/browser.test.js

Closes #2021

The browser logger exposed Logger#setBindings in types, but the runtime
implementation in browser.js did not define it. Calling setBindings on a
browser logger caused a TypeError, even though setBindings is a supported
Logger API in pino.

Implement browser logger setBindings by storing the new bindings and
rebuilding level methods so subsequent logs include updated binding
objects. Add browser tests to verify setBindings applies bindings and can
overwrite existing bindings.

Fixes pinojs#2021
@mibragimov mibragimov marked this pull request as ready for review March 7, 2026 14:25
@mcollina
Copy link
Member

mcollina commented Mar 8, 2026

CI is red

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bug] logger.setBindings undefined when using esm exported pino

2 participants