Skip to content

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

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

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

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

Depends on #910 — this branch contains it (the start.js path cannot even run without those interop fixes; rebase after that merges if needed).

@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
kilisamemarisaaa force-pushed the fix/logger-instance-routing branch from f24a76a to 53f6329 Compare August 29, 2026 03:04
@kilisamemarisaaa

Copy link
Copy Markdown
Author

Thanks for the review @Tony133 — you're right, the branch was cut from the #910
branch and carried its commits. I've rebuilt the branch on top of the latest
upstream/main so it now contains only the logger-instance change (single
commit); CI is rerunning on the clean history.

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