Skip to content

fix(core): isolate logger per rsbuild instance#7369

Merged
chenjiahan merged 2 commits intomainfrom
codex/fix-instance-logger
Mar 23, 2026
Merged

fix(core): isolate logger per rsbuild instance#7369
chenjiahan merged 2 commits intomainfrom
codex/fix-instance-logger

Conversation

@chenjiahan
Copy link
Copy Markdown
Member

Summary

This PR changes the default Rsbuild instance logger to use a dedicated logger created by createLogger() instead of the shared global logger, so instance-level logger mutations no longer leak across instances. It also keeps the debug override behavior consistent for created loggers, moves logger-specific assertions into a dedicated test file, and updates the related API docs.

Related Links

None

Copilot AI review requested due to automatic review settings March 23, 2026 08:19
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request focuses on isolating the logger instance for each Rsbuild instance to prevent unintended side effects and improve the overall reliability of the logging system. It also includes updates to the testing and documentation to ensure consistency and clarity.

Highlights

  • Logger Isolation: The default Rsbuild instance logger now uses a dedicated logger created by createLogger(), preventing instance-level logger mutations from leaking across instances.
  • Consistent Debug Override: The debug override behavior is now consistent for created loggers.
  • Test Updates: Logger-specific assertions have been moved into a dedicated test file.
  • Documentation Updates: Related API documentation has been updated to reflect the changes.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@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 effectively isolates the logger for each rsbuild instance, preventing state leakage between them. The implementation is clean, with good refactoring of the logger override logic and comprehensive test coverage for the new behavior. The documentation has also been updated accordingly. I've found a minor issue where custom log writers are bypassed by the debug log override, and I've provided suggestions to address it.

Comment thread packages/core/src/logger.ts
Comment thread packages/core/src/logger.ts
Copy link
Copy Markdown
Contributor

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 isolates the default Rsbuild instance logger by creating a dedicated logger per createRsbuild() instance (instead of reusing the shared global logger), preventing logger mutations from leaking across instances.

Changes:

  • Create a per-instance default logger via createLogger() and plumb it into createContext().
  • Apply consistent debug override behavior to loggers created via createLogger().
  • Move logger-related assertions into a dedicated test file and update API/docs to reflect the new behavior.

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
website/docs/zh/config/custom-logger.mdx Updates Chinese docs to describe per-instance default logger behavior.
website/docs/zh/api/javascript-api/instance.mdx Updates Chinese API docs for rsbuild.logger fallback behavior.
website/docs/en/config/custom-logger.mdx Updates English docs to describe per-instance default logger behavior.
website/docs/en/api/javascript-api/instance.mdx Updates English API docs for rsbuild.logger fallback behavior.
packages/core/tests/logger.test.ts Adds focused tests for instance logger isolation and custom logger exposure.
packages/core/tests/default.test.ts Removes logger assertions now covered by the dedicated logger test file.
packages/core/src/types/rsbuild.ts Updates type docs to reflect per-instance created logger fallback.
packages/core/src/types/plugin.ts Clarifies plugin API logger docs regarding config.customLogger.
packages/core/src/logger.ts Extracts/apply debug override logic to reuse for created loggers.
packages/core/src/createRsbuild.ts Switches default logger from global singleton to createLogger() per instance; passes logger into context creation.
packages/core/src/createContext.ts Accepts logger as a parameter and stores it on the context (no longer selects default internally).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread website/docs/en/config/custom-logger.mdx
Comment thread website/docs/en/api/javascript-api/instance.mdx
Comment thread website/docs/zh/config/custom-logger.mdx
Comment thread website/docs/zh/api/javascript-api/instance.mdx
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f83889ee85

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

: configOrFactory || {};

const logger = config.customLogger ?? defaultLogger;
const logger = config.customLogger ?? createLogger();
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Preserve global logger overrides in default instances

Programmatic callers that customize the exported logger singleton (for example with logger.override(...) or logger.level = 'silent') and then call createRsbuild() without customLogger will silently lose those settings here, because the instance now starts from a fresh createLogger() instead of the configured singleton. That breaks the existing logger.override() workflow documented in website/docs/en/api/javascript-api/core.mdx and the previous javascript-api/custom-logger coverage: logger.override({ ready: ... }); await createRsbuild().build() no longer affects build/dev logs unless the caller also discovers they must pass customLogger: logger.

Useful? React with 👍 / 👎.

Comment thread e2e/cases/custom-logger/global-override/rsbuild.config.ts
@chenjiahan chenjiahan merged commit 3474d21 into main Mar 23, 2026
5 checks passed
@chenjiahan chenjiahan deleted the codex/fix-instance-logger branch March 23, 2026 09:04
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.

2 participants