Repository: pinojs/pino
Pull request #1123 (2021-09-09 17:17:18)

Removed multistream prettyPrint deprecation and clean up docs


Patch:
diff --git a/docs/api.md b/docs/api.md
index 6348689..342ff6d 100644
--- a/docs/api.md
+++ b/docs/api.md
@@ -453,9 +453,6 @@ set on the `destination` object after each log line is written:
 * the last logger instance as `destination.lastLogger` (to support child
   loggers)
 
-For a full reference for using `Symbol.for('pino.metadata')`, see the [`pino-multi-stream` ⇗](https://github.com/pinojs/pino-multi-stream)
-module.
-
 The following is a succinct usage example:
 
 ```js
@@ -470,8 +467,6 @@ console.log(
 ) // Logged message "hi" at level 30 with object { a: 1 } at time 1531590545089
 ```
 
-* See [`pino-multi-stream` ⇗](https://github.com/pinojs/pino-multi-stream)
-
 <a id="logger"></a>
 ## Logger Instance
 
@@ -678,7 +673,7 @@ the current log level of the parent at the time they are spawned.
 
 The log level of a child is mutable. It can be set independently
 of the parent either by setting the [`level`](#level) accessor after creating
-the child logger or using the reserved [`bindings.level`](#bindingslevel-string) key.
+the child logger or using the [`options.level`](#optionslevel-string) key.
 
 #### `bindings` (Object)
 
@@ -695,18 +690,6 @@ child.info('child!')
 
 The `bindings` object may contain any key except for reserved configuration keys `level` and `serializers`.
 
-##### `bindings.level` (String)
-
-If a `level` property is present in the `bindings` object passed to `logger.child`
-it will override the child logger level.
-
-```js
-const logger = pino()
-logger.debug('nope') // will not log, since default level is info
-const child = logger.child({foo: 'bar', level: 'debug'})
-child.debug('debug!') // will log as the `level` property set the level to debug
-```
-
 ##### `bindings.serializers` (Object) - DEPRECATED
 
 Use `options.serializers` instead.
@@ -715,6 +698,19 @@ Use `options.serializers` instead.
 
 Options for child logger. These options will override the parent logger options.
 
+##### `options.level` (String)
+
+The `level` property overrides the log level of the child logger.
+By default the parent log level is inherited.
+After the creation of the child logger, it is also accessible using the [`logger.level`](#logger-level) key.
+
+```js
+const logger = pino()
+logger.debug('nope') // will not log, since default level is info
+const child = logger.child({foo: 'bar'}, {level: 'debug')
+child.debug('debug!') // will log as the `level` property set the level to debug
+```
+
 ##### `options.redact` (Array | Object)
 
 Setting `options.redact` to an array or object will override the parent `redact` options. To remove `redact` options inherited from the parent logger set this value as an empty array (`[]`).
@@ -1055,8 +1051,10 @@ Create a stream composed by multiple destination streams:
 ```js
 var fs = require('fs')
 var pino = require('pino')
+var pretty = require('pino-pretty')
 var streams = [
   {stream: fs.createWriteStream('/tmp/info.stream.out')},
+  {stream: pretty() },
   {level: 'debug', stream: fs.createWriteStream('/tmp/debug.stream.out')},
   {level: 'fatal', stream: fs.createWriteStream('/tmp/fatal.stream.out')}
 ]
@@ -1079,7 +1077,7 @@ In order for `multistream` to work, the log level __must__ be set to the lowest
 
 + `dedupe`: Set this to `true` to send logs only to the stream with the higher level. Default: `false`
 
-    `dedupe` flag can be useful for example when using pino-multi-stream to redirect `error` logs to `process.stderr` and others to `process.stdout`:
+    `dedupe` flag can be useful for example when using `pino.multistream` to redirect `error` logs to `process.stderr` and others to `process.stdout`:
 
     ```js
     var pino = require('pino')
diff --git a/lib/deprecations.js b/lib/deprecations.js
index 5d09ee6..13ffe6d 100644
--- a/lib/deprecations.js
+++ b/lib/deprecations.js
@@ -5,12 +5,4 @@ module.exports = warning
 
 const warnName = 'PinoWarning'
 
-warning.create(warnName, 'PINODEP004', 'bindings.serializers is deprecated, use options.serializers option instead')
-
-warning.create(warnName, 'PINODEP005', 'bindings.formatters is deprecated, use options.formatters option instead')
-
-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/proto.js b/lib/proto.js
index a6e1f47..a4c5619 100644
--- a/lib/proto.js
+++ b/lib/proto.js
@@ -3,7 +3,6 @@
 /* eslint no-prototype-builtins: 0 */
 
 const { EventEmitter } = require('events')
-const warning = require('./deprecations')
 const {
   lsCacheSym,
   levelValSym,
@@ -85,22 +84,6 @@ function child (bindings, options) {
   const formatters = this[formattersSym]
   const instance = Object.create(this)
 
-  if (bindings.hasOwnProperty('serializers') === true) {
-    warning.emit('PINODEP004')
-    options.serializers = bindings.serializers
-  }
-  if (bindings.hasOwnProperty('formatters') === true) {
-    warning.emit('PINODEP005')
-    options.formatters = bindings.formatters
-  }
-  if (bindings.hasOwnProperty('customLevels') === true) {
-    warning.emit('PINODEP006')
-    options.customLevels = bindings.customLevels
-  }
-  if (bindings.hasOwnProperty('level') === true) {
-    warning.emit('PINODEP007')
-    options.level = bindings.level
-  }
   if (options.hasOwnProperty('serializers') === true) {
     instance[serializersSym] = Object.create(null)
 
diff --git a/lib/tools.js b/lib/tools.js
index 63bb746..7a9dc80 100644
--- a/lib/tools.js
+++ b/lib/tools.js
@@ -461,6 +461,14 @@ function final (logger, handler) {
   })
 
   if (!hasHandler) {
+    try {
+      stream.flushSync()
+    } catch {
+      // it's too late to wait for the stream to be ready
+      // because this is a final tick scenario.
+      // in practice there shouldn't be a situation where it isn't
+      // however, swallow the error just in case (and for easier testing)
+    }
     return finalLogger
   }
 


Test patch:
diff --git a/test/deprecations.test.js b/test/deprecations.test.js
deleted file mode 100644
index 48c5892..0000000
--- a/test/deprecations.test.js
+++ /dev/null
@@ -1,149 +0,0 @@
-'use strict'
-/* eslint no-prototype-builtins: 0 */
-
-const { hostname } = require('os')
-const { test } = require('tap')
-const { sink, once } = require('./helper')
-const pino = require('../')
-
-process.removeAllListeners('warning')
-
-test('child(bindings.serializers)', async ({ match, equal, pass }) => {
-  process.on('warning', onWarning)
-  function onWarning (warn) {
-    equal(warn.code, 'PINODEP004')
-  }
-
-  const stream = sink()
-  const parent = pino({ serializers: { test: () => 'parent' } }, stream)
-  const child = parent.child({
-    serializers: {
-      test () {
-        pass('called')
-        return 'child'
-      }
-    }
-  })
-
-  const o = once(stream, 'data')
-  child.fatal({ test: 'test' })
-  match(await o, { test: 'child' })
-  process.removeListener('warning', onWarning)
-})
-
-test('child(bindings.formatters)', async ({ match, equal, pass }) => {
-  process.on('warning', onWarning)
-  function onWarning (warn) {
-    equal(warn.code, 'PINODEP005')
-  }
-
-  const stream = sink()
-  const logger = pino({
-    formatters: {
-      level (label, number) {
-        return {
-          log: {
-            level: label
-          }
-        }
-      },
-      bindings (bindings) {
-        return {
-          process: {
-            pid: bindings.pid
-          },
-          host: {
-            name: bindings.hostname
-          }
-        }
-      },
-      log (obj) {
-        return { hello: 'world', ...obj }
-      }
-    }
-  }, stream)
-
-  const child = logger.child({
-    foo: 'bar',
-    nested: { object: true },
-    formatters: {
-      bindings (bindings) {
-        pass('called')
-        return { ...bindings, faz: 'baz' }
-      }
-    }
-  })
-
-  const o = once(stream, 'data')
-  child.info('hello world')
-  match(await o, {
-    log: {
-      level: 'info'
-    },
-    process: {
-      pid: process.pid
-    },
-    host: {
-      name: hostname()
-    },
-    hello: 'world',
-    foo: 'bar',
-    nested: { object: true },
-    faz: 'baz'
-  })
-  process.removeListener('warning', onWarning)
-})
-
-test('child(bindings.customLevels)', async ({ match, equal, pass }) => {
-  process.on('warning', onWarning)
-  function onWarning (warn) {
-    equal(warn.code, 'PINODEP006')
-  }
-
-  const stream = sink()
-  const logger = pino(stream).child({
-    childMsg: 'ok',
-    customLevels: {
-      foo: 35
-    }
-  }, {
-    formatters: {
-      level (label, number) {
-        if (label === 'foo' && number === 35) {
-          pass('using customLevels')
-        }
-        return { level: number }
-      }
-    }
-  })
-
-  const o = once(stream, 'data')
-  logger.foo('test')
-  match(await o, {
-    level: 35,
-    childMsg: 'ok',
-    msg: 'test'
-  })
-  process.removeListener('warning', onWarning)
-})
-
-test('child(bindings.level)', async ({ equal, pass }) => {
-  process.on('warning', onWarning)
-  function onWarning (warn) {
-    equal(warn.code, 'PINODEP007')
-  }
-
-  const stream = sink()
-  const logger = pino({
-    level: 'info'
-  }, stream).child({
-    level: 'trace'
-  })
-
-  const o = once(stream, 'data')
-  logger.info('test')
-  if (await o === null) {
-    pass('child can overrid parent level')
-  }
-  process.removeListener('warning', onWarning)
-})
diff --git a/test/final.test.js b/test/final.test.js
index 300f59d..4828920 100644
--- a/test/final.test.js
+++ b/test/final.test.js
@@ -72,6 +72,32 @@ test('listener function immediately sync flushes when fired (sync true)', async
   if (passed === false) fail('flushSync not called')
 })
 
+test('immediately sync flushes when no handler is provided (sync false)', async ({ pass, fail }) => {
+  const dest = pino.destination({ dest: getPathToNull(), sync: false })
+  let passed = false
+  dest.flushSync = () => {
+    passed = true
+    pass('flushSync called')
+    dest.flushSync = () => {}
+  }
+  pino.final(pino(dest))
+  await sleep(10)
+  if (passed === false) fail('flushSync not called')
+})
+
+test('immediately sync flushes when no handler is provided (sync true)', async ({ pass, fail }) => {
+  const dest = pino.destination({ dest: getPathToNull(), sync: true })
+  let passed = false
+  dest.flushSync = () => {
+    passed = true
+    pass('flushSync called')
+    dest.flushSync = () => {}
+  }
+  pino.final(pino(dest))
+  await sleep(10)
+  if (passed === false) fail('flushSync not called')
+})
+
 test('swallows the non-ready error', async ({ doesNotThrow }) => {
   const dest = pino.destination({ dest: getPathToNull(), sync: false })
   doesNotThrow(() => {
diff --git a/test/is-level-enabled.test.js b/test/is-level-enabled.test.js
index dc5e119..8df8b88 100644
--- a/test/is-level-enabled.test.js
+++ b/test/is-level-enabled.test.js
@@ -26,7 +26,7 @@ test('can check if lower level is disabled', async ({ equal }) => {
 })
 
 test('can check if child has current level enabled', async ({ equal }) => {
-  const log = pino().child({ level: 'debug' })
+  const log = pino().child({}, { level: 'debug' })
   equal(true, log.isLevelEnabled('debug'))
   equal(true, log.isLevelEnabled('error'))
   equal(false, log.isLevelEnabled('trace'))
diff --git a/test/multistream.test.js b/test/multistream.test.js
index 6bae9c8..ff363d3 100644
--- a/test/multistream.test.js
+++ b/test/multistream.test.js
@@ -7,6 +7,8 @@ const os = require('os')
 const test = require('tap').test
 const pino = require('../')
 const multistream = pino.multistream
+const proxyquire = require('proxyquire')
+const strip = require('strip-ansi')
 
 test('sends to multiple streams using string levels', function (t) {
   let messageCount = 0
@@ -213,23 +215,24 @@ test('supports custom levels', function (t) {
 })
 
 test('supports pretty print', function (t) {
+  t.plan(2)
   const stream = writeStream(function (data, enc, cb) {
-    t.not(data.toString().match(/INFO.*: pretty print/), null)
-    t.end()
+    t.not(strip(data.toString()).match(/INFO.*: pretty print/), null)
     cb()
   })
-  const outStream = pino({
-    prettyPrint: {
-      levelFirst: true,
-      colorize: false
+
+  const pretty = proxyquire('pino-pretty', {
+    'sonic-boom': function () {
+      t.pass('sonic created')
+      return stream
     }
-  }, stream)
+  })
 
   const log = pino({
     level: 'debug',
     name: 'helloName'
   }, multistream([
-    { stream: outStream[pino.symbols.streamSym] }
+    { stream: pretty() }
   ]))
 
   log.info('pretty print')