From c2247f3930f29e406fb5d116c43f79b262005d1a Mon Sep 17 00:00:00 2001 From: Matteo Collina Date: Wed, 8 Sep 2021 12:37:03 +0200 Subject: [PATCH 1/2] Deprecate the prettyPrint option Fixes https://github.com/pinojs/pino/issues/1106 --- lib/deprecations.js | 2 ++ lib/tools.js | 2 ++ test/pretty.test.js | 16 ++++++++++++++++ 3 files changed, 20 insertions(+) diff --git a/lib/deprecations.js b/lib/deprecations.js index 4c8f0a5cd..5d09ee6aa 100644 --- a/lib/deprecations.js +++ b/lib/deprecations.js @@ -12,3 +12,5 @@ warning.create(warnName, 'PINODEP005', 'bindings.formatters is deprecated, use o warning.create(warnName, 'PINODEP006', 'bindings.customLevels is deprecated, use options.customLevels option instead') warning.create(warnName, 'PINODEP007', 'bindings.level is deprecated, use options.level option instead') + +warning.create(warnName, 'PINODEP008', 'prettyPrint is deprecated, use the pino-pretty transport instead') diff --git a/lib/tools.js b/lib/tools.js index c3502a9bc..a238c1957 100644 --- a/lib/tools.js +++ b/lib/tools.js @@ -6,6 +6,7 @@ const format = require('quick-format-unescaped') const { mapHttpRequest, mapHttpResponse } = require('pino-std-serializers') const SonicBoom = require('sonic-boom') const stringifySafe = require('json-stringify-safe') +const warning = require('./deprecations') const { lsCacheSym, chindingsSym, @@ -419,6 +420,7 @@ function createArgsNormalizer (defaultOptions) { stream = buildSafeSonicBoom({ fd: stream.fd, sync: true }) } if (prettyPrint) { + warning.emit('PINODEP008') const prettyOpts = Object.assign({ messageKey }, prettyPrint) stream = getPrettyStream(prettyOpts, prettifier, stream, instance) } diff --git a/test/pretty.test.js b/test/pretty.test.js index b44e627c0..3fe30af9d 100644 --- a/test/pretty.test.js +++ b/test/pretty.test.js @@ -9,6 +9,22 @@ const { once } = require('./helper') const pino = require('../') const strip = require('strip-ansi') +// silence warnings +process.removeAllListeners('warning') + +// This test MUST be the first +test('deprecation', ({ equal, plan }) => { + plan(1) + + process.once('warning', function (warning) { + equal(warning.code, 'PINODEP008') + }) + + pino({ + prettyPrint: true + }) +}) + test('can be enabled via exported pino function', async ({ not }) => { let actual = '' const child = execa(process.argv[0], [join(__dirname, 'fixtures', 'pretty', 'basic.js')]) From fa4e75b89343357d2dc29b8e644e87989f608fba Mon Sep 17 00:00:00 2001 From: Matteo Collina Date: Wed, 8 Sep 2021 12:45:04 +0200 Subject: [PATCH 2/2] Docs for the deprecation --- docs/api.md | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/docs/api.md b/docs/api.md index 697a22a1b..ec357fdda 100644 --- a/docs/api.md +++ b/docs/api.md @@ -347,6 +347,8 @@ and searching for logged objects can start from a consistent path. Default: `false` +__DEPRECATED: use [`transport`](#transport) instead. + Enables pretty printing log logs. This is intended for non-production configurations. This may be set to a configuration object as outlined in the [`pino-pretty` documentation](https://github.com/pinojs/pino-pretty). @@ -934,11 +936,7 @@ const pino = require('pino') const transports = pino.transport({ targets: [{ level: 'info', - target: 'some-transport', - options: { some: 'options for', the: 'transport' } - }, { - level: 'info', - target: 'pino-pretty' + target: 'pino-pretty' // must be installed separately }, { level: 'trace', target: 'pino/file',