Skip to content

Commit

Permalink
Deprecation warning for pino.final() in Node v14+ (#1199)
Browse files Browse the repository at this point in the history
  • Loading branch information
sameer-coder authored Nov 2, 2021
1 parent 9ba4117 commit 6c53815
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/deprecations.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
3 changes: 3 additions & 0 deletions lib/tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
}
Expand Down
23 changes: 23 additions & 0 deletions test/final.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down

0 comments on commit 6c53815

Please sign in to comment.