Skip to content

browser: forward remaining log arguments to write in asObject mode - #2496

Open
SnowingFox wants to merge 1 commit into
pinojs:mainfrom
SnowingFox:fix/2244-asobject-write-args
Open

browser: forward remaining log arguments to write in asObject mode#2496
SnowingFox wants to merge 1 commit into
pinojs:mainfrom
SnowingFox:fix/2244-asobject-write-args

Conversation

@SnowingFox

Copy link
Copy Markdown

Fixes #2244

Problem

When a custom browser.write is used (which forces asObject mode), extra arguments passed to the log methods never reach the write function:

const logger = pino({ browser: { write: (logObj, ...logParams) => { /* ... */ } } })
logger.debug('bla', { di: 'da' })

Here { di: 'da' } is silently dropped: logParams is always empty because asObject() only returns the formatted log object.

asObjectBindingsOnly mode already forwards the remaining arguments (return [formattedLogObject, ...argsCloned]), but the regular asObject branch dropped them.

Change

Mirror the asObjectBindingsOnly branch in browser.js and return the remaining (unconsumed) arguments alongside the formatted log object:

return [formattedLogObject, ...argsCloned]

Verification

Added a regression test in test/browser.test.js:

  • logger.info('test', { di: 'da' }) now calls write(logObj, { di: 'da' }).

The new test fails on main and passes with this change:

npx tape test/browser.test.js

@luantaraschi luantaraschi left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I reproduced the reported behavior against the parent commit: the custom write function received only the formatted log object. At this head it also receives the untouched { di: 'da' } argument, while the formatted object still contains the expected level, message, and timestamp.

I also ran the complete test/browser.test.js file (196 assertions), ESLint on the changed files, and git diff --check. All passed. The change is limited to forwarding the arguments that remain after the log object is formatted, consistent with the existing asObjectBindingsOnly path.

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.

browser: logger does not pass arguments to write function

2 participants