From 10bfff4a22138229f3ae0acac2d5a824ce9f0c1c Mon Sep 17 00:00:00 2001 From: Steven Li <55261196+stevel032@users.noreply.github.com> Date: Tue, 11 Jun 2024 08:09:05 -0700 Subject: [PATCH] =?UTF-8?q?Fixing=20browser=20side=20child=20log=20issue?= =?UTF-8?q?=20(#960)=20child=20level=20can=20now=20be=20set=20at=20cr?= =?UTF-8?q?=E2=80=A6=20(#1986)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 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 --- browser.js | 2 +- test/browser-child.test.js | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/browser.js b/browser.js index 8560f1f99..f65ad7678 100644 --- a/browser.js +++ b/browser.js @@ -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 } diff --git a/test/browser-child.test.js b/test/browser-child.test.js index 0ed1dd515..db80e7ee1 100644 --- a/test/browser-child.test.js +++ b/test/browser-child.test.js @@ -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',