From b066628693d9d9a526b3e8ab2a2d493aad38a722 Mon Sep 17 00:00:00 2001 From: "Fred K. Schott" Date: Mon, 7 Feb 2022 05:23:01 -0800 Subject: [PATCH] improve debug logs (#2537) * improve debug logs * Update logger.ts --- .changeset/many-oranges-retire.md | 5 +++++ packages/astro/src/cli/index.ts | 10 +++++++--- packages/astro/src/core/logger.ts | 8 +++++++- 3 files changed, 19 insertions(+), 4 deletions(-) create mode 100644 .changeset/many-oranges-retire.md diff --git a/.changeset/many-oranges-retire.md b/.changeset/many-oranges-retire.md new file mode 100644 index 0000000000..40b099fb1f --- /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 3860d9bbab..b37edec1c7 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 c00e71347a..84bc968fcf 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. */