Skip to content

Commit

Permalink
feat: print debug logs when set DEBUG env (web-infra-dev#977)
Browse files Browse the repository at this point in the history
  • Loading branch information
chenjiahan authored Dec 17, 2023
1 parent 80a19ad commit 85a3d29
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
6 changes: 6 additions & 0 deletions .changeset/thin-cobras-cheat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@rsbuild/shared': patch
'@rsbuild/core': patch
---

feat: print debug logs when set DEBUG env
7 changes: 7 additions & 0 deletions packages/core/src/cli/prepare.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion packages/shared/src/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
}
};

Expand Down

0 comments on commit 85a3d29

Please sign in to comment.