Skip to content

Conversation

duyhungtnn
Copy link
Collaborator

@duyhungtnn duyhungtnn commented Oct 1, 2025

I found this issue while investigating an error in OpenFeature Node.js e2e
I saw a log with the prefix “error,” but it was not actually an error—it was a misleading message caused by incorrect logic in the DefaultLogger..

Issues with the Original DefaultLogger Implementation

  • Incorrect Console Method Usage
    All log messages, regardless of level (debug, info, warn, error), were output using console.error. This caused all logs to appear as errors, even when they were informational or debug messages.

  • Log Message Suppression
    The logger did not output messages if only a single argument was provided (e.g., logger.error('something')), due to an unnecessary args.length === 1 check.

  • Static Prefix Assignment
    The log message prefix was set based on the logger’s configured level, not the actual level of the message being logged. This could result in misleading prefixes.

  • Unnecessary Complexity
    The use of a separate write() method added complexity and made the code harder to maintain, especially since the logic could be handled more simply and clearly.

@duyhungtnn duyhungtnn requested a review from cre8ivejp as a code owner October 1, 2025 08:05
@duyhungtnn duyhungtnn requested review from Copilot and removed request for cre8ivejp October 1, 2025 08:07
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes critical logging issues in the DefaultLogger class, correcting incorrect console method usage and log level handling that was causing all messages to appear as errors with misleading prefixes.

  • Replaces incorrect static prefix assignment with dynamic level-based prefixes
  • Fixes console method selection to use appropriate methods (error, warn, info, debug) instead of always using console.error
  • Removes unnecessary single-argument suppression and simplifies the logging logic

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Introduces a logLevelIndices map for more efficient log level lookups and simplifies the DefaultLogger implementation. This change improves performance and code readability by avoiding repeated array searches.
@duyhungtnn duyhungtnn requested a review from cre8ivejp October 1, 2025 08:41
@duyhungtnn
Copy link
Collaborator Author

duyhungtnn commented Oct 1, 2025

please help me to take a look @cre8ivejp

@duyhungtnn duyhungtnn changed the title fix: correct print level for the DefaultLogger fix: incorrect print level for the DefaultLogger Oct 1, 2025
it will look like `destroy finished Timeout`
this.featureFlagProcessor?.stop();
this.segementUsersCacheProcessor?.stop();
this.config.logger?.info('destroy finished', this.registerEventsScheduleID);
this.config.logger?.info('destroy finished');
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

it was like

destroy finished Timeout {
      _idleTimeout: -1,
      _idlePrev: null,
      _idleNext: null,
      _idleStart: 5616,
      _onTimeout: null,
      _timerArgs: undefined,
      _repeat: 30000,
      _destroyed: true,
      [Symbol(refed)]: true,
      [Symbol(kHasPrimitive)]: false,
      [Symbol(asyncId)]: 644,
      [Symbol(triggerId)]: 0
    }

It made me feel like something bad had happened, but it hadn’t.

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.

1 participant