Skip to content

fix(@angular/cli): restore console methods after logger completes#32828

Merged
clydin merged 1 commit intoangular:mainfrom
oBusk:rebind-console-log
Mar 25, 2026
Merged

fix(@angular/cli): restore console methods after logger completes#32828
clydin merged 1 commit intoangular:mainfrom
oBusk:rebind-console-log

Conversation

@oBusk
Copy link
Contributor

@oBusk oBusk commented Mar 24, 2026

PR Checklist

Please check to confirm your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • Other... Please describe:

What is the current behavior?

Issue Number: N/A

console.log() when called after finally will be dropped. This could become an issue if code prints late like eslint which uses process.on("exit") to print timing information. This code will run after the logger has completed and will be dropped.

This means that TIMING=all ng lint does not work, eventhough eslint is seeing the var and collecting the data, but fails to print because console.log() is dead.

What is the new behavior?

Once the logger is completed, we reinsert console.log, console.info, console.warn and console.error so that any console logs that happens to trigger as the process is exiting, will still be printed to stdout.

Maybe there's a way to keep the logger living for longer, but since it's doing asyncronous things, I don't think we can clean it up in process.on('exit') or similiar? This fix at least prints to stdout as a best effort.

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

Ran into this issue by trying to print the timing information when using ng lint (angular-eslint), and realised that they werent doing anything weird, the console log was running, it was just disapparing. After some more tracking I realised that angular-cli was the one hijacking console.log(), so hoping to clean out this little tripwire.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces the restoration of original console methods (log, info, warn, error) in the finally block to ensure consistent output from late consumers. The review suggests an improvement to make this restoration more robust and explicit by storing all original console methods in a single object to avoid assumptions and potential issues with chained assignments during restoration.

Copy link
Collaborator

@alan-agius4 alan-agius4 left a comment

Choose a reason for hiding this comment

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

LGTM, thanks

@alan-agius4 alan-agius4 added target: patch This PR is targeted for the next patch release action: merge The PR is ready for merge by the caretaker labels Mar 25, 2026
@clydin clydin merged commit 4bbd1bf into angular:main Mar 25, 2026
38 checks passed
@clydin
Copy link
Member

clydin commented Mar 25, 2026

This PR was merged into the repository. The changes were merged into the following branches:

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

Labels

action: merge The PR is ready for merge by the caretaker area: @angular/cli target: patch This PR is targeted for the next patch release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants