Skip to content

Conversation

mag123c
Copy link
Contributor

@mag123c mag123c commented Aug 5, 2025

PR Checklist

Please check if 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
  • Other... Please describe:

What is the current behavior?

Currently, ConsoleLogger always uses process.stdout.write() and process.stderr.write() for output.
This causes issues in test environments like Jest, which can buffer console.* calls but not direct stream writes. making it difficult to capture or suppress log output during tests.

Issue Number: #15483

What is the new behavior?

Added a new forceConsole option to ConsoleLoggerOptions that, when set to true, forces the logger to use console.log() and console.error() instead of process.stdout.write() and process.stderr.write().

This allows test frameworks like Jest to properly buffer and capture log output, making tests cleaner and enabling log assertion testing.

Example usage:

const logger = new ConsoleLogger({ forceConsole: true });

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

@coveralls
Copy link

coveralls commented Aug 5, 2025

Pull Request Test Coverage Report for Build b1e13942-5596-47d2-81bc-03960211f858

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 88.913%

Totals Coverage Status
Change from base Build a08fe13a-23f1-40a9-9d85-ee98e3227002: 0.0%
Covered Lines: 7282
Relevant Lines: 8190

💛 - Coveralls

* This is useful for test environments like Jest that can buffer console calls.
* @default false
*/
forceConsole?: boolean;
Copy link

@yawhide yawhide Aug 5, 2025

Choose a reason for hiding this comment

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

if i dont ever instantiate this class, i won't be able to set this to true right?

can we add a config so that when i do NestFactory.create(...), i can set the forceConsole to true?

@mag123c mag123c force-pushed the feat/add-forceconsole-option-to-logger branch from 9e72cb9 to ff81fb1 Compare August 7, 2025 05:13
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