docs: document debug logging (#4457)

This commit is contained in:
Ben McCann 2021-08-01 07:53:55 -07:00 committed by GitHub
parent 304cc6b87b
commit 1e711c0ef6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 3 deletions

View File

@ -75,6 +75,10 @@ test('?raw import', async () => {
})
```
## Debug Logging
You can set the `DEBUG` environment variable to turn on debugging logs. E.g. `DEBUG="vite:resolve"`. To see all debug logs you can set `DEBUG="vite:*"`, but be warned that it will be quite noisy. You can run `grep -r "createDebugger('vite:" packages/vite/src/` to see a list of available debug scopes.
## Pull Request Guidelines
- Checkout a topic branch from a base branch, e.g. `main`, and merge back against that branch.

View File

@ -58,13 +58,16 @@ interface DebuggerOptions {
onlyWhenFocused?: boolean | string
}
export type ViteDebugScope = `vite:${string}`
export function createDebugger(
ns: string,
namespace: ViteDebugScope,
options: DebuggerOptions = {}
): debug.Debugger['log'] {
const log = debug(ns)
const log = debug(namespace)
const { onlyWhenFocused } = options
const focus = typeof onlyWhenFocused === 'string' ? onlyWhenFocused : ns
const focus =
typeof onlyWhenFocused === 'string' ? onlyWhenFocused : namespace
return (msg: string, ...args: any[]) => {
if (filter && !msg.includes(filter)) {
return