-
-
Notifications
You must be signed in to change notification settings - Fork 272
docs: add customLogger config docs #7367
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| --- | ||
| description: 'Use customLogger to attach a logger instance to the current Rsbuild instance. Create it with createLogger() for isolated logging.' | ||
| --- | ||
|
|
||
| # customLogger | ||
|
|
||
| - **Type:** [Logger](/api/javascript-api/core#logger) | ||
| - **Default:** `undefined` | ||
|
|
||
| Uses a custom logger instance for the current Rsbuild instance. | ||
|
|
||
| ## Example | ||
|
|
||
| Use [createLogger](/api/javascript-api/core#createlogger) to create a new logger instance. | ||
|
|
||
| ```ts title="rsbuild.config.ts" | ||
| import { createLogger, defineConfig } from '@rsbuild/core'; | ||
|
|
||
| const logger = createLogger({ | ||
| level: 'warn', | ||
| }); | ||
|
|
||
| export default defineConfig({ | ||
| customLogger: logger, | ||
| }); | ||
| ``` | ||
|
|
||
| ## Global logger vs instance logger | ||
|
|
||
| Rsbuild provides two ways to access a logger: | ||
|
|
||
| - The global logger is the shared [logger](/api/javascript-api/core#logger) singleton exported from `@rsbuild/core`. | ||
| - The instance logger is the logger associated with the current Rsbuild instance, exposed as [rsbuild.logger](/api/javascript-api/instance#rsbuildlogger) or [api.logger](/plugins/dev/core#apilogger) in plugins. | ||
|
|
||
| When `customLogger` is not set, the instance logger falls back to the shared global logger. When `customLogger` is set, the instance logger references that custom logger instead. | ||
|
|
||
| ## Version history | ||
|
|
||
| | Version | Changes | | ||
| | ------- | ------------------------------- | | ||
| | v2.0.0 | Added the `customLogger` option | | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| --- | ||
| description: '为当前 Rsbuild 实例指定独立的 logger。推荐配合 createLogger() 创建,避免修改共享 logger。' | ||
| --- | ||
|
|
||
| # customLogger | ||
|
|
||
| - **类型:** [Logger](/api/javascript-api/core#logger) | ||
| - **默认值:** `undefined` | ||
|
|
||
| 为当前 Rsbuild 实例指定一个自定义 logger。 | ||
|
chenjiahan marked this conversation as resolved.
|
||
|
|
||
| ## 示例 | ||
|
|
||
| 使用 [createLogger](/api/javascript-api/core#createlogger) 来创建一个新的 logger 实例。 | ||
|
|
||
| ```ts title="rsbuild.config.ts" | ||
| import { createLogger, defineConfig } from '@rsbuild/core'; | ||
|
|
||
| const logger = createLogger({ | ||
| level: 'warn', | ||
| }); | ||
|
|
||
| export default defineConfig({ | ||
| customLogger: logger, | ||
| }); | ||
| ``` | ||
|
|
||
| ## 全局 logger 与实例 logger | ||
|
|
||
| Rsbuild 提供了两种获取 logger 的方式: | ||
|
|
||
| - 全局 logger 是从 `@rsbuild/core` 导出的共享 [logger](/api/javascript-api/core#logger) 单例。 | ||
| - 实例 logger 是当前 Rsbuild 实例关联的 logger,可以通过 [rsbuild.logger](/api/javascript-api/instance#rsbuildlogger) 获取,在插件中也可以通过 [api.logger](/plugins/dev/core#apilogger) 获取。 | ||
|
|
||
| 当未配置 `customLogger` 时,实例 logger 会回退到共享的全局 logger;当配置了 `customLogger` 时,实例 logger 则会引用该自定义 logger。 | ||
|
|
||
| ## 版本历史 | ||
|
|
||
| | 版本 | 变更内容 | | ||
| | ------ | ------------------------ | | ||
| | v2.0.0 | 新增 `customLogger` 选项 | | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.