parent
f9a9ef394b
commit
b066628693
3 changed files with 19 additions and 4 deletions
5
.changeset/many-oranges-retire.md
Normal file
5
.changeset/many-oranges-retire.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
'astro': patch
|
||||
---
|
||||
|
||||
Improve debug logs
|
|
@ -1,7 +1,7 @@
|
|||
/* eslint-disable no-console */
|
||||
|
||||
import type { AstroConfig } from '../@types/astro';
|
||||
import type { LogOptions } from '../core/logger.js';
|
||||
import { enableVerboseLogging, LogOptions } from '../core/logger.js';
|
||||
|
||||
import * as colors from 'kleur/colors';
|
||||
import fs from 'fs';
|
||||
|
@ -83,9 +83,13 @@ export async function cli(args: string[]) {
|
|||
dest: defaultLogDestination,
|
||||
level: 'info',
|
||||
};
|
||||
if (flags.verbose) {
|
||||
logging.level = 'debug';
|
||||
enableVerboseLogging();
|
||||
} else if (flags.silent) {
|
||||
logging.level = 'silent';
|
||||
}
|
||||
|
||||
if (flags.verbose) logging.level = 'debug';
|
||||
if (flags.silent) logging.level = 'silent';
|
||||
let config: AstroConfig;
|
||||
try {
|
||||
config = await loadConfig({ cwd: projectRoot, flags });
|
||||
|
|
|
@ -89,6 +89,12 @@ export const levels: Record<LoggerLevel, number> = {
|
|||
silent: 90,
|
||||
};
|
||||
|
||||
export function enableVerboseLogging() {
|
||||
debugPackage.enable('*,-babel');
|
||||
debug('cli', '--verbose flag enabled! Enabling: DEBUG="*,-babel"');
|
||||
debug('cli', 'Tip: Set the DEBUG env variable directly for more control. Example: "DEBUG=astro:*,vite:* astro build".');
|
||||
}
|
||||
|
||||
/** Full logging API */
|
||||
export function log(opts: LogOptions = {}, level: LoggerLevel, type: string | null, ...args: Array<any>) {
|
||||
const logLevel = opts.level ?? defaultLogOptions.level;
|
||||
|
@ -118,7 +124,7 @@ const debuggers: Record<string, debugPackage.Debugger['log']> = {};
|
|||
export function debug(type: string, ...messages: Array<any>) {
|
||||
const namespace = `astro:${type}`;
|
||||
debuggers[namespace] = debuggers[namespace] || debugPackage(namespace);
|
||||
return debuggers[namespace](messages);
|
||||
return debuggers[namespace](...messages);
|
||||
}
|
||||
|
||||
/** Emit a user-facing message. Useful for UI and other console messages. */
|
||||
|
|
Loading…
Reference in a new issue