7

I have this simple function that I created to log whatever happens in my code:

const pino = require('pino')

module.exports = pino({
  transport: {
    target: "pino-pretty",
    options: {
      translateTime: "SYS:dd-mm-yyyy HH:MM:ss",
      ignore: "pid,hostname",
      destination: './logs/logs.txt'
    }
  }
})

The problem with destination. If this option is, pino will write everything in file, not in console, if there is not, will print in console, but not in file. I want to print in console and write logs at the same time.

Is this possible?

dokichan
  • 857
  • 2
  • 11
  • 44

1 Answers1

6

I know this is old, but I thought I'd drop this in as I'm working with it right now.

transport: {
    targets: [
        {
            level: 'info',
            target: 'pino-pretty',
            options: {}
        },
        {
            level: 'trace',
            target: 'pino/file',
            options: { destination: './pino-logger.log' }
        }
    ],
},

You can set up multiple targets and distinguish which will receive what levels and options. Hope that helps anyone still looking around.