Skip to content

Commit

Permalink
Merge pull request #65 from targos/fix-sprintf-v4
Browse files Browse the repository at this point in the history
fix: support falsy value in sprintf substitution
  • Loading branch information
thetutlage authored Feb 8, 2024
2 parents d77c024 + b40a9c7 commit 7d8593e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
8 changes: 1 addition & 7 deletions src/Logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

/**
Expand Down
5 changes: 5 additions & 0 deletions test/logger.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand All @@ -109,6 +110,10 @@ test.group('Logger', () => {
level: 30,
msg: `hello info ${JSON.stringify({ url: '/' })}`,
},
{
level: 30,
msg: 'total: 0',
},
]
)
})
Expand Down

0 comments on commit 7d8593e

Please sign in to comment.