node.jspinojs

How to use pino-transport in nodejs for logs.?


const pino = require('pino')
const transport = pino.transport({
  targets: [{
    level: 'info',
    target: 'pino-pretty' // must be installed separately
  }, {
    level: 'trace',
    target: 'pino/file',
    options: { destination: '/path/to/store/logs' }
  }]
})
pino(transport)

enter image description here

Why I am getting this error pino.transport is not a function...?


Solution

  • It is because your project is using pino version 6.x.

    Transports were introduced in v7.x or later