Skip to content

Commit

Permalink
Fixing browser side child log issue (#960) child level can now be set…
Browse files Browse the repository at this point in the history
… at cr… (#1986)

* Fixing browser side child log issue, child level can now be set at creation time, #960

* Added test case for setting child logger level at creation time (#960)

---------

Co-authored-by: Steven Li <steve98@gmail.com>
  • Loading branch information
stevel032 and smx-stevel committed Jun 11, 2024
1 parent 8db130e commit 10bfff4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ function pino (opts) {
// must happen before the level is assigned
appendChildLogger(this, newLogger)
// required to actually initialize the logger functions for any given child
newLogger.level = this.level
newLogger.level = childOptions.level || this.level // allow level to be set by childOptions

return newLogger
}
Expand Down
12 changes: 12 additions & 0 deletions test/browser-child.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,18 @@ test('child has parent level', ({ end, same, is }) => {
end()
})

test('child can set level at creation time', ({ end, same, is }) => {
const instance = pino({
level: 'error',
browser: {}
})

const child = instance.child({}, { level: 'info' }) // first bindings, then options

same(child.level, 'info')
end()
})

test('changing child level does not affect parent', ({ end, same, is }) => {
const instance = pino({
level: 'error',
Expand Down

0 comments on commit 10bfff4

Please sign in to comment.