Skip to content

fix: allow loggerInstance in server and plugin options - #930

Open
dax-side wants to merge 1 commit into
fastify:mainfrom
dax-side:fix-logger-instance
Open

dax-side wants to merge 1 commit into
fastify:mainfrom
dax-side:fix-logger-instance

Conversation

@dax-side

@dax-side dax-side commented Nov 5, 2026

Copy link
Copy Markdown

Whenever you use fastify start it will add a logger option { level } to your server options. As of fastify v5 we need to provide a logger instance via loggerInstance and if both are provided fastify will throw an error. So providing options = { loggerInstance: pino() } with the -o flag, or passing { loggerInstance } as the server options to helper.build()/helper.listen(), results in an error on startup.

Fixes this issue by omitting logger from the cli if there is a loggerInstance in the combined options.

Added 2 test cases to test/helper.test.js. One for each case.

Refs #574, #618

Checklist

@SameRainbows

Copy link
Copy Markdown

Tested locally on Node 24.

Key points verified:

  • Fastify Core throws FST_ERR_LOG_INVALID_LOGGER ("You cannot specify both logger and loggerInstance") if both properties are passed during initialization. Because fastify-cli defaults options.logger = { level: opts.logLevel }, providing a custom logger via server options or module.exports.options.loggerInstance crashed at startup.
  • Removing options.logger when options.loggerInstance is set resolves the conflict without impacting CLI flags like --log-level when a custom logger is not supplied.
  • Both test cases in test/helper.test.js pass cleanly.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants