Skip to content

Restore logger state after each fshToFhir call - #1646

Open
cpruijsen wants to merge 1 commit into
FHIR:masterfrom
cpruijsen:fix/issue-1645
Open

cpruijsen wants to merge 1 commit into
FHIR:masterfrom
cpruijsen:fix/issue-1645

Conversation

@cpruijsen

Copy link
Copy Markdown
Contributor

Description:

fshToFhir saves both silent and level on the process-wide winston logger, applies options.logLevel, then restores them in finally, including on the invalid-logLevel return and when processing throws. After logLevel: 'silent', logger.transports[0].silent stayed true, so a later call with logLevel: 'error' (or with no option) still wrote nothing. After logLevel: 'error', logger.level stayed 'error' for later calls that omitted the option. Errors and warnings in the returned object were already correct; only console logging leaked.

'silent' is not a winston level. It sets the Console transport's silent flag, so restoring logger.level alone is not enough.

The reporter's sequence in #1645 is the spec:

await fshToFhir('', { logLevel: 'silent' });
await fshToFhir('', { logLevel: 'error' });
await fshToFhir('');

Restore both fields in try/finally rather than resetting to info / not-silent at the start of each call and leaving the last call's settings on the logger (that restore stops a silent call from muting every other logger user in the process, and matches the existing save/restore pattern in withDebugLogging and restoreMainLogger). Reset-at-start would also make sequential fshToFhir calls independent, but it would leave the singleton muted (or at error) after return. Happy to switch to reset-at-start if you want logger.level to remain 'error' after a call.

Tests for during-call application use the existing loadExternalDependencies spy (it runs after logLevel is applied). New cases live in a #LoggerIsolation describe so they do not collide with the #EndToEnd work on #1642.

Most of the src/run/FshToFhir.ts diff is re-indentation inside the new try; hiding whitespace shows the actual change.

Testing Instructions:

  • npm test -- test/run/FshToFhir.test.ts
  • In a Node REPL or script that imports fshToFhir, run the three-call sequence from fshToFhir does not reset the logger between calls #1645 and confirm the second call is not silent and the third is back at the default info level.
  • Ran here: npm test -- test/run/FshToFhir.test.ts (16 passed; 5 of them fail on master), tsc --noEmit, and prettier --check / eslint on the two changed files.

Related Issue:

Fixes #1645

fshToFhir applied logLevel to the process-wide winston logger and never
put it back, so a silent call left every later call muted.
@cmoesel

cmoesel commented Sep 30, 2026

Copy link
Copy Markdown
Member

Thank you @cpruijsen for this PR. I apologize for the delay in reviewing it. I had a couple of large and complicated PRs that I had to get through first. I just merged one of them (#1637) today and I'm working my way through #1641 next. I hope to review the remaining PRs soon after that.

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.

fshToFhir does not reset the logger between calls

2 participants