Skip to content

Instantly share code, notes, and snippets.

@joeytwiddle
Last active June 12, 2025 11:44
Show Gist options
  • Select an option

  • Save joeytwiddle/e7cccc1e3adc83512220078ec62d61e7 to your computer and use it in GitHub Desktop.

Select an option

Save joeytwiddle/e7cccc1e3adc83512220078ec62d61e7 to your computer and use it in GitHub Desktop.
Logging in Fastify

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")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment