Skip to content

Latest commit

 

History

History
167 lines (112 loc) · 3.97 KB

legacy.md

File metadata and controls

167 lines (112 loc) · 3.97 KB

Legacy

Legacy Node Support

Node v4

Node v4 is supported on the Pino v4 line.

Node v0.10-v0.12

Node v0.10 or Node v0.12 is supported on the Pino v2 line.

Documentation

Pino v4 Documentation

https://github.com/pinojs/pino/tree/v4.x.x/docs

Pino v3 Documentation

https://github.com/pinojs/pino/tree/v3.x.x/docs

Pino v2 Documentation

https://github.com/pinojs/pino/tree/v2.x.x/docs

Migration

Pino v4 to to Pino v5

Logging Destination

In Pino v4 the destination could be set by passing a stream as the second parameter to the exported pino function. This is still the case in v5. However it's strongly recommended to use pino.destination which will write logs ~30% faster.

v4
const stdoutLogger = require('pino')()
const stderrLogger = require('pino')(process.stderr)
const fileLogger = require('pino')(fs.createWriteStream('/log/path'))
v5
const stdoutLogger = require('pino')() // pino.destination by default
const stderrLogger = require('pino')(pino.destination(2))
const fileLogger = require('pino')(pino.destination('/log/path'))

Note: This is not a breaking change, WritableStream instances are still supported, but are slower than pino.destination which uses the high speed sonic-boom library.

Extreme Mode

The extreme setting does not exist as an option in Pino v5, instead use a pino.extreme destination.

v4
const stdoutLogger = require('pino')({extreme: true})
const stderrLogger = require('pino')({extreme: true}, process.stderr)
const fileLogger = require('pino')({extreme: true}, fs.createWriteStream('/log/path'))
v5
const stdoutLogger = require('pino')(pino.extreme())
const stderrLogger = require('pino')(pino.extreme(2))
const fileLogger = require('pino')(pino.extreme('/log/path'))

Pino CLI is now pino-pretty CLI

The Pino CLI is provided with Pino v4 for basic log prettification.

From Pino v5 the CLI is installed separately with pino-pretty.

v4
$ npm install -g pino
$ node app.js | pino
v5
$ npm install -g pino-pretty
$ node app.js | pino-pretty

Programmatic Pretty Printing

The pino.pretty() method has also been removed from Pino v5.

v4
var pino = require('pino')
var pretty = pino.pretty()
pretty.pipe(process.stdout)
v5

Instead use the prettyPrint option (also available in v4):

const logger = require('pino')({
  prettyPrint: process.env.NODE_ENV !== 'production'
})

In v5 the pretty-print module must be installed to use the prettyPrint option:

npm install --save-dev pino-pretty

Slowtime

In Pino v4 a slowtime option was supplied, which allowed for full ISO dates in the timestamps instead of milliseconds since the Epoch. In Pino v5 this has been completely removed, along with the pino.stdTimeFunctions.slowTime function. In order to achieve the equivalent in v5, a custom time function should be supplied:

v4
const pino = require('pino')
const logger = pino({slowtime: true})
// following avoids deprecation warning in v4:
const loggerAlt = pino({timestamp: pino.stdTimeFunctions.slowTime})
v5
const logger = require('pino')({
  timestamp: () => ',"time":"' + (new Date()).toISOString() + '"'
})

The practice of creating ISO dates in-process for logging purposes is strongly recommended against. Instead consider post-processing the logs or using a transport to convert the timestamps.