Skip to content

feat: export createLogger to create isolated logger instances#7353

Merged
chenjiahan merged 2 commits intomainfrom
create_logger_0320
Mar 21, 2026
Merged

feat: export createLogger to create isolated logger instances#7353
chenjiahan merged 2 commits intomainfrom
create_logger_0320

Conversation

@chenjiahan
Copy link
Copy Markdown
Member

Summary

Added a createLogger function that creates new logger instances with their own state, allowing for custom log levels and avoiding mutation of the shared logger singleton.

Checklist

  • Tests updated (or not required).
  • Documentation updated (or not required).

Copilot AI review requested due to automatic review settings March 20, 2026 09:51
@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 introduces a new createLogger function, enabling developers to generate isolated logger instances. This enhancement addresses the previous limitation where all Rsbuild instances shared a single global logger, preventing custom log levels or configurations per instance. By providing createLogger, users can now manage logging more flexibly for specific components or plugins without unintended side effects on the main application's logging behavior.

Highlights

  • New createLogger Function: A createLogger function has been exported, allowing developers to create independent logger instances with their own state and custom log levels.
  • Isolated Logger Instances: This new function addresses the limitation of the previously shared global logger singleton, preventing unintended mutations and enabling more flexible logging configurations per instance.
  • Test Coverage: A new test case was added to verify that createLogger successfully produces distinct logger instances that respect custom log level settings.
  • Documentation Updates: The documentation has been updated in both English and Chinese to introduce createLogger and clarify the usage and limitations of the shared logger instance.
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 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.

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 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 createLogger wrapper around rslog.createLogger and export it from @rsbuild/core.
  • Update English/Chinese docs to document createLogger and clarify the shared logger limitations.
  • Add a unit test to verify createLogger is 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.

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: 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".

@cloudflare-workers-and-pages
Copy link
Copy Markdown

Deploying rsbuild with  Cloudflare Pages  Cloudflare Pages

Latest commit: 1b0668d
Status:🚫  Build failed.

View logs

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.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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
})

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Agreed, I will try to implement a customLogger option later.

@chenjiahan chenjiahan merged commit c3dd373 into main Mar 21, 2026
10 checks passed
@chenjiahan chenjiahan deleted the create_logger_0320 branch March 21, 2026 08:59
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.

3 participants