diff --git a/.changeset/thin-cobras-cheat.md b/.changeset/thin-cobras-cheat.md new file mode 100644 index 0000000000..d2f4bf2073 --- /dev/null +++ b/.changeset/thin-cobras-cheat.md @@ -0,0 +1,6 @@ +--- +'@rsbuild/shared': patch +'@rsbuild/core': patch +--- + +feat: print debug logs when set DEBUG env diff --git a/packages/core/src/cli/prepare.ts b/packages/core/src/cli/prepare.ts index 0032d13532..0ee8ce7b39 100644 --- a/packages/core/src/cli/prepare.ts +++ b/packages/core/src/cli/prepare.ts @@ -9,8 +9,15 @@ function initNodeEnv() { } } +function initLogger() { + if (process.env.DEBUG) { + logger.level = 'verbose'; + } +} + export function prepareCli() { initNodeEnv(); + initLogger(); // If not called through a package manager, // output a blank line to keep the greet log nice. diff --git a/packages/shared/src/logger.ts b/packages/shared/src/logger.ts index 811323d3df..525e33fa63 100644 --- a/packages/shared/src/logger.ts +++ b/packages/shared/src/logger.ts @@ -19,7 +19,7 @@ export const debug = (message: string | (() => string)) => { const { performance } = require('perf_hooks'); const result = typeof message === 'string' ? message : message(); const time = color.gray(`[${performance.now().toFixed(2)} ms]`); - console.error(`${color.bold(color.yellow('debug'))} ${result} ${time}`); + logger.debug(`${result} ${time}`); } };