feat(browser): support pino.multistream and a destination argument by kilisamemarisaaa · Pull Request #2523 · pinojs/pino · GitHub
Skip to content

feat(browser): support pino.multistream and a destination argument - #2523

Open
kilisamemarisaaa wants to merge 2 commits into
pinojs:mainfrom
kilisamemarisaaa:feat/browser-multistream
Open

kilisamemarisaaa wants to merge 2 commits into
pinojs:mainfrom
kilisamemarisaaa:feat/browser-multistream

Conversation

@kilisamemarisaaa

Copy link
Copy Markdown

Summary

Closes #1686

The browser build did not export pino.multistream, so pino.multistream() threw a TypeError in the browser. lib/multistream.js has no Node.js-only dependencies, so the browser build now reuses it verbatim.

pino() also accepts the destination as its second argument, matching the Node.js signature. When a multistream result (or any object with a write method) is passed, each log line is routed through destination.write() with lastLevel set, so per-stream level filtering applies exactly as in Node.

The written payload is the same object the browser.write option would receive (an entry with time, level, msg and any bindings); asObject is implied when a destination is used. browser.write users are unaffected.

Documented differences from Node.js

  • The lastTime / lastMsg / lastObj metadata fields are not propagated in the browser.
  • The payload is a log entry object rather than a JSON line.

docs/browser.md moves pino.multistream() out of the Node.js-only statics list and documents the browser usage.

Validation

  • New test/browser-multistream.test.js (7 tests): per-stream level filtering, bare destination, default info stream level, child logger bindings routing, setBindings reflection, and the destination validation error.
  • Full suite: npx borp --timeout 60000 'test/*test.js' → 460 pass / 0 fail on this branch.
  • npx eslint browser.js test/browser-multistream.test.js clean.

The browser build did not export pino.multistream, so pino.multistream()
threw a TypeError in the browser (issue pinojs#1686). lib/multistream.js has
no Node.js-only dependencies, so the browser build now reuses it
verbatim.

pino() also accepts the destination as its second argument, matching the
Node.js signature: when a multistream result (or any object with a write
method) is passed, each log line is routed to destination.write() with
lastLevel set, so the per-stream level filtering applies. The written
payload is the same object the browser.write option would receive (an
entry with time, level, msg and bindings); asObject is implied.

Differences from Node.js, documented in docs/browser.md: the
lastTime / lastMsg / lastObj metadata fields are not propagated, and
the payload is a log entry object rather than a JSON line.

Co-Authored-By: EvoX <evox@evomap.ai>
Comment thread browser.js Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you use a for loop instead?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replaced forEach with an indexed for loop in 95a2ddf. The per-iteration const preserves the level captured by each destination writer. Verified the browser multistream cases (7 cases / 11 assertions) and the complete npm test pipeline, including lint, runtime coverage, Jest and types. On Windows I added the existing Git usr/bin directory to the process PATH to supply mv for the unchanged fixture script.

This branch has not been deployed

No deployments
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.

multistream is not a function on browser.

2 participants