diff --git a/.changeset/many-oranges-retire.md b/.changeset/many-oranges-retire.md new file mode 100644 index 000000000..40b099fb1 --- /dev/null +++ b/.changeset/many-oranges-retire.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Improve debug logs diff --git a/packages/astro/src/cli/index.ts b/packages/astro/src/cli/index.ts index 3860d9bba..b37edec1c 100644 --- a/packages/astro/src/cli/index.ts +++ b/packages/astro/src/cli/index.ts @@ -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 }); diff --git a/packages/astro/src/core/logger.ts b/packages/astro/src/core/logger.ts index c00e71347..84bc968fc 100644 --- a/packages/astro/src/core/logger.ts +++ b/packages/astro/src/core/logger.ts @@ -89,6 +89,12 @@ export const levels: Record = { 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) { const logLevel = opts.level ?? defaultLogOptions.level; @@ -118,7 +124,7 @@ const debuggers: Record = {}; export function debug(type: string, ...messages: Array) { 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. */