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 the message string as the second argument!
  • If you want to log an error, it must be the first argument, and not deep inside an object.
  • (I don't know how to log an error and also an object for context, but it might be possible)

Working patterns:

fastify.log.info("message")
fastify.log.info(error, "message")
fastify.log.info({ data }, "message")

Patterns which don't work:

// Only logs: { error: "[object Error]" }
fastify.log.info({ error }, "message")

// Only logs the message!
fastify.log.info("message", { data })
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment