diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc index deeb9c8dd0..913ff76d85 100644 --- a/CHANGELOG.asciidoc +++ b/CHANGELOG.asciidoc @@ -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 diff --git a/lib/logging.js b/lib/logging.js index 504df89c46..b3605ccee8 100644 --- a/lib/logging.js +++ b/lib/logging.js @@ -30,6 +30,7 @@ var ecsFormat = require('@elastic/ecs-pino-format') var pino = require('pino') +var semver = require('semver') const DEFAULT_LOG_LEVEL = 'info' @@ -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 })