Skip to content

fix: pass logger instances via loggerInstance (fastify v5 rejects instances in logger) - #911

Closed
kilisamemarisaaa wants to merge 1 commit into
fastify:mainfrom
kilisamemarisaaa:fix/logger-instance-routing
Closed

fix: pass logger instances via loggerInstance (fastify v5 rejects instances in logger)#911
kilisamemarisaaa wants to merge 1 commit into
fastify:mainfrom
kilisamemarisaaa:fix/logger-instance-routing

Conversation

@kilisamemarisaaa

@kilisamemarisaaa kilisamemarisaaa commented Aug 28, 2026

Copy link
Copy Markdown

Summary

fastify v5 only accepts a configuration object in the logger option and throws FST_ERR_LOG_INVALID_LOGGER_CONFIG when given an instance — instances must go through loggerInstance. fastify-cli converges user-provided logger instances — from --logging-module (#775), --options files (the setup described in #574), or server options — into options.logger, so passing a real Pino instance crashes fastify start at startup:

FastifyError [Error]: logger options only accepts a configuration object.
    code: 'FST_ERR_LOG_INVALID_LOGGER_CONFIG'

This was invisible to the suite because the only logger tests use a config-object fixture (test/data/custom-logger.js = { name, customLevels: {...} }); the instance path had zero coverage.

Fix: after all option merges converge in start.js, route any logger value exposing child() to loggerInstance (4 lines). Config-object loggers (including the existing fixtures and the { level } default) are untouched.

Regression test: -L with a fixture exporting a real Pino instance; asserts the logger level survives into fastify.log.

Verification

@Tony133 Tony133 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are the same commits as in this PR: #910 Can you create a clean PR with the changes described? Or do a rebase?

fastify v5 throws FST_ERR_LOG_INVALID_LOGGER_CONFIG when a logger
instance is passed through the `logger` option (it only accepts a
configuration object there). fastify-cli converges user-provided logger
instances -- from --logging-module, --options files or server options --
into options.logger, so --logging-module with a real Pino instance
crashed at startup.

Route instances to loggerInstance after all option merges, and add a
regression test with a real Pino instance fixture: the existing tests
only used a config-object fixture, so the instance path had zero
coverage.

Co-Authored-By: EvoX <evox@evomap.ai>
@kilisamemarisaaa

This comment was marked as spam.

@kilisamemarisaaa

This comment was marked as spam.

@kilisamemarisaaa

This comment was marked as spam.

@Fdawgs Fdawgs closed this Aug 31, 2026
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.

3 participants