feat: export createLogger to create isolated logger instances#7353
feat: export createLogger to create isolated logger instances#7353chenjiahan merged 2 commits intomainfrom
createLogger to create isolated logger instances#7353Conversation
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 introduces a new 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 introduces a createLogger function to allow creating isolated logger instances, which is a great addition to prevent mutation of the shared singleton. The implementation is straightforward, and it's good to see that it's accompanied by a test and documentation updates.
I've found one area for improvement regarding the consistency of the debug log format between the shared logger and newly created instances. My suggestion aims to align their behavior.
There was a problem hiding this comment.
Pull request overview
This PR introduces a new public API createLogger in @rsbuild/core to allow consumers (custom code/plugins) to create isolated logger instances with independent state, and updates the docs/tests accordingly.
Changes:
- Add
createLoggerwrapper aroundrslog.createLoggerand export it from@rsbuild/core. - Update English/Chinese docs to document
createLoggerand clarify the sharedloggerlimitations. - Add a unit test to verify
createLoggeris exported and returns a distinct instance.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| website/docs/zh/config/log-level.mdx | Clarifies log-level limitations and points users to createLogger for isolated loggers. |
| website/docs/zh/api/javascript-api/core.mdx | Documents the new createLogger API and updates logger docs to reference it. |
| website/docs/en/config/log-level.mdx | Clarifies log-level limitations and points users to createLogger for isolated loggers. |
| website/docs/en/api/javascript-api/core.mdx | Documents the new createLogger API and updates logger docs to reference it. |
| packages/core/tests/index.test.ts | Adds a basic export/instance-isolation test for createLogger. |
| packages/core/src/logger.ts | Implements createLogger and ties debug-mode default level behavior to DEBUG. |
| packages/core/src/index.ts | Exposes createLogger as part of the public API surface. |
💡 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: b3bef19c3a
ℹ️ 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".
| A shared logger instance based on [rslog](https://github.com/rstackjs/rslog), used to output log information in a unified format. Use this instead of `console.log` to maintain consistent logging with Rsbuild. | ||
|
|
||
| Based on [rslog](https://github.com/rstackjs/rslog). | ||
| If you need isolated logger state for different Rsbuild instances or plugins, use [createLogger](#createlogger) instead of mutating this singleton instance. |
There was a problem hiding this comment.
I want every instance has its own logger
instance2:start building...
instance1:start building...
instance1:done built in 0.2s
instance2:done built in 3s
There was a problem hiding this comment.
import { createRslog } from 'rslog';
import { createRsbuild } from '@rsbuild/core';
const logger1 = createRslog();
const rsbuildInstance1 = createRsbuild({
logger: logger1
});
const logger2 = createRslog()
logger2.overrides({
// ...
})
const rsbuildInstance2 = createRsbuild({
logger: logger2
})There was a problem hiding this comment.
Agreed, I will try to implement a customLogger option later.
Summary
Added a
createLoggerfunction that creates new logger instances with their own state, allowing for custom log levels and avoiding mutation of the sharedloggersingleton.Checklist