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?

1

1 Answer 1

7

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.