diff --git a/lib/deprecations.js b/lib/deprecations.js index a6f4d7873..d6c622416 100644 --- a/lib/deprecations.js +++ b/lib/deprecations.js @@ -6,3 +6,5 @@ module.exports = warning const warnName = 'PinoWarning' warning.create(warnName, 'PINODEP008', 'prettyPrint is deprecated, look at https://github.com/pinojs/pino-pretty for alternatives.') + +warning.create(warnName, 'PINODEP009', 'The use of pino.final is discouraged in Node.js v14+ and not required. It will be removed in the next major version') diff --git a/lib/tools.js b/lib/tools.js index f32fe53a6..10a48bbc3 100644 --- a/lib/tools.js +++ b/lib/tools.js @@ -437,6 +437,9 @@ function createArgsNormalizer (defaultOptions) { } function final (logger, handler) { + const major = Number(process.versions.node.split('.')[0]) + if (major >= 14) warning.emit('PINODEP009') + if (typeof logger === 'undefined' || typeof logger.child !== 'function') { throw Error('expected a pino logger instance') } diff --git a/test/final.test.js b/test/final.test.js index 4828920fa..14faf32cc 100644 --- a/test/final.test.js +++ b/test/final.test.js @@ -8,6 +8,29 @@ const { sleep, getPathToNull } = require('./helper') // will be emitted. Let's raise this so we do not scare everybody. process.setMaxListeners(100) +test('should show warning for pino.final on node 14+', ({ equal, end, plan }) => { + const major = Number(process.versions.node.split('.')[0]) + if (major < 14) return end() + + plan(1) + const dest = pino.destination({ dest: getPathToNull(), sync: false }) + dest.flushSync = () => {} + const instance = pino(dest) + + pino.final(instance, (_, finalLogger) => { + finalLogger.info('hello') + })() + + function onWarning (warning) { + equal(warning.code, 'PINODEP009') + end() + } + + process.once('warning', onWarning) + + instance.info('hello') +}) + test('replaces onTerminated option', async ({ throws }) => { throws(() => { pino({