mirror of
https://github.com/withastro/astro.git
synced 2025-01-20 22:12:38 -05:00
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 */
|
/* eslint-disable no-console */
|
||||||
|
|
||||||
import type { AstroConfig } from '../@types/astro';
|
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 * as colors from 'kleur/colors';
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
|
@ -83,9 +83,13 @@ export async function cli(args: string[]) {
|
||||||
dest: defaultLogDestination,
|
dest: defaultLogDestination,
|
||||||
level: 'info',
|
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;
|
let config: AstroConfig;
|
||||||
try {
|
try {
|
||||||
config = await loadConfig({ cwd: projectRoot, flags });
|
config = await loadConfig({ cwd: projectRoot, flags });
|
||||||
|
|
|
@ -89,6 +89,12 @@ export const levels: Record<LoggerLevel, number> = {
|
||||||
silent: 90,
|
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 */
|
/** Full logging API */
|
||||||
export function log(opts: LogOptions = {}, level: LoggerLevel, type: string | null, ...args: Array<any>) {
|
export function log(opts: LogOptions = {}, level: LoggerLevel, type: string | null, ...args: Array<any>) {
|
||||||
const logLevel = opts.level ?? defaultLogOptions.level;
|
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>) {
|
export function debug(type: string, ...messages: Array<any>) {
|
||||||
const namespace = `astro:${type}`;
|
const namespace = `astro:${type}`;
|
||||||
debuggers[namespace] = debuggers[namespace] || debugPackage(namespace);
|
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. */
|
/** Emit a user-facing message. Useful for UI and other console messages. */
|
||||||
|
|
Loading…
Add table
Reference in a new issue