summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Fred K. Schott <fkschott@gmail.com> 2022-02-07 05:23:01 -0800
committerGravatar GitHub <noreply@github.com> 2022-02-07 08:23:01 -0500
commitb066628693d9d9a526b3e8ab2a2d493aad38a722 (patch)
treec5992bca894c89b35b11fc47becd07d6587b1cde
parentf9a9ef394b424f604a4bc7a179282536ac1fc65f (diff)
downloadastro-b066628693d9d9a526b3e8ab2a2d493aad38a722.tar.gz
astro-b066628693d9d9a526b3e8ab2a2d493aad38a722.tar.zst
astro-b066628693d9d9a526b3e8ab2a2d493aad38a722.zip
improve debug logs (#2537)
* improve debug logs * Update logger.ts
Diffstat (limited to '')
-rw-r--r--.changeset/many-oranges-retire.md5
-rw-r--r--packages/astro/src/cli/index.ts10
-rw-r--r--packages/astro/src/core/logger.ts8
3 files changed, 19 insertions, 4 deletions
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<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. */