Skip to content

Commit

Permalink
fix: adapt logger.child call to new pino 6 format (#2333)
Browse files Browse the repository at this point in the history
This avoids a possible PINODEP004 warning if a given custom logger
is Pino >=6.0.0 <6.12.0.

Fixes #2332
  • Loading branch information
Marsup authored Nov 1, 2021
1 parent d5a268d commit b869458
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ This fixes an issue with context binding of EventEmitters, where
`removeListener` would fail to actually remove if the same handler function was
added to multiple events.
* Fix pino's deprecation warning when using a custom logger with pino@6 ({issues}2332[#2332])
[[release-notes-3.23.0]]
==== 3.23.0 2021/10/25
Expand Down
6 changes: 6 additions & 0 deletions lib/logging.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

var ecsFormat = require('@elastic/ecs-pino-format')
var pino = require('pino')
var semver = require('semver')

const DEFAULT_LOG_LEVEL = 'info'

Expand Down Expand Up @@ -116,6 +117,11 @@ function createLogger (levelName, customLogger) {
// Is this a pino logger? If so, it supports the API the agent requires and
// can be used directly. We must add our custom serializers.
if (Symbol.for('pino.serializers') in customLogger) {
// Pino added `options` second arg to `logger.child` in 6.12.0.
if (semver.gte(customLogger.version, '6.12.0')) {
return customLogger.child({}, { serializers })
}

return customLogger.child({
serializers: serializers
})
Expand Down

0 comments on commit b869458

Please sign in to comment.