improve debug logs (#2537)

* improve debug logs

* Update logger.ts
This commit is contained in:
Fred K. Schott 2022-02-07 05:23:01 -08:00 committed by GitHub
parent f9a9ef394b
commit b066628693
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 4 deletions

View file

@ -0,0 +1,5 @@
---
'astro': patch
---
Improve debug logs

View file

@ -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 });

View file

@ -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. */