Skip to content

fix(core): restore logger after silent lazy module load - #17631

Merged
kamilmysliwiec merged 1 commit into
nestjs:masterfrom
shariyerShazan:fix/lazy-module-loader-logger
Aug 30, 2026
Merged

kamilmysliwiec merged 1 commit into
nestjs:masterfrom
shariyerShazan:fix/lazy-module-loader-logger

Conversation

@shariyerShazan

Copy link
Copy Markdown
Contributor

Fixes #17628

What was wrong

Calling lazyModuleLoader.load(ModuleA, { logger: false }) replaced the shared InstanceLoader's logger with a SilentLogger, but this was never reverted. As a result, passing { logger: false } once permanently silenced InstanceLoader logging for every subsequent lazy module load in the application's lifetime.

Why it happened

registerLoggerConfiguration only ever set the logger to SilentLogger when logger === false — it never captured the original logger or restored it afterward:

private registerLoggerConfiguration(loadOpts?: LazyModuleLoaderLoadOptions) {
  if (loadOpts?.logger === false) {
    this.instanceLoader.setLogger(new SilentLogger());
  }
}

Since instanceLoader is a shared, application-scoped singleton, this mutation persisted across all future load() calls, regardless of their own logger option.

What was changed

load() now captures the InstanceLoader's logger before silencing it, and restores it in a finally block once the current load() call completes — ensuring the silencing is scoped to that single invocation, even if an error is thrown during loading.

How it was tested

Why the change is safe

The change only affects the logger reference held by InstanceLoader during and immediately after a load() call with { logger: false }. Calls without that option are unaffected, since no silencing (and therefore no restoration) occurs for them.

LazyModuleLoader.load() with { logger: false } replaced the shared
InstanceLoader logger with a SilentLogger but never restored it,
permanently silencing logs for all subsequent load() calls.

Fixes nestjs#17628
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

LazyModuleLoader.load({ logger: false }) permanently silences InstanceLoader logging for all subsequent lazy loads

2 participants