fix(core): isolate logger per rsbuild instance#7369
Conversation
Summary of ChangesHello, 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
Using Gemini Code AssistThe 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
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 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
|
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 intocreateContext(). - 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.
There was a problem hiding this comment.
💡 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(); |
There was a problem hiding this comment.
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 👍 / 👎.
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