0

I'm using fastify and pino-pretty

pino.info('Error doing that', Error) <- prints {} for Error

pino.info(Error, 'Error doing that') <- prints the error in full

All my other logging, uses the more natural message,data format

Is there a way to switch the way pino processes the params to allow for objects/errors in the second param?

Titan
  • 5,567
  • 9
  • 55
  • 90

1 Answers1

0

Solution given by @jsumners in Fastify discord

https://getpino.io/#/docs/api?id=logmethod

const hooks = {
  logMethod (inputArgs, method, level) {
    if (inputArgs.length >= 2) {
      const arg1 = inputArgs.shift()
      const arg2 = inputArgs.shift()
      return method.apply(this, [arg2, arg1, ...inputArgs])
    }
    return method.apply(this, inputArgs)
  }
}
Titan
  • 5,567
  • 9
  • 55
  • 90