TLDR:
- If you want to log an object, put the object as the first argument, and (optionally) a message string as the second argument.
- If you want to log an error object, it must be the first argument, and not a property inside an object.
- (As a result, I don't know how to log an error and also an object for context, but it might be possible.)
Patterns which are WORKING:
fastify.log.info("message")
fastify.log.info(error, "message")
fastify.log.info({ data }, "message")Patterns which DO NOT WORK:
// Only logs the message, ignores the data object!
fastify.log.info("message", { data })
// Only logs: { error: "[object Error]" }
fastify.log.info({ error }, "message")