From b40a9c755441c7c243226bec88cbcf4eec6cc001 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Zasso?= Date: Thu, 8 Feb 2024 15:31:00 +0100 Subject: [PATCH] fix: support falsy value in sprintf substitution --- src/Logger.ts | 8 +------- test/logger.spec.ts | 5 +++++ 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/Logger.ts b/src/Logger.ts index bad31b1..57f6ed7 100644 --- a/src/Logger.ts +++ b/src/Logger.ts @@ -119,13 +119,7 @@ export class Logger implements LoggerContract { public log(level: string, message: string, ...values: any[]): void public log(level: string, mergingObject: any, message: string, ...values: any[]): void public log(level: string, mergingObject: any, message: string, ...values: any[]): void { - if (values.length) { - this.pino[level](mergingObject, message, ...values) - } else if (message) { - this.pino[level](mergingObject, message) - } else { - this.pino[level](mergingObject) - } + this.pino[level](mergingObject, message, ...values) } /** diff --git a/test/logger.spec.ts b/test/logger.spec.ts index 5fbd9c0..64fbe27 100644 --- a/test/logger.spec.ts +++ b/test/logger.spec.ts @@ -90,6 +90,7 @@ test.group('Logger', () => { logger.info('hello %s', 'info') logger.info('hello %s %o', 'info', { url: '/' }) logger.info('hello %s %j', 'info', { url: '/' }) + logger.info('total: %d', 0) assert.deepEqual( messages.map((m) => { @@ -109,6 +110,10 @@ test.group('Logger', () => { level: 30, msg: `hello info ${JSON.stringify({ url: '/' })}`, }, + { + level: 30, + msg: 'total: 0', + }, ] ) })