Set the default log level to info (#326)
* Set the default log level to info * Adds the changeset * Let the logger.js be the source of truth
This commit is contained in:
parent
a893b4a921
commit
5a871f357f
6 changed files with 18 additions and 12 deletions
5
.changeset/hot-laws-allow.md
Normal file
5
.changeset/hot-laws-allow.md
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
'astro': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Fixes logging to default to the info level
|
|
@ -18,11 +18,11 @@ import { buildCollectionPage, buildStaticPage, getPageType } from './build/page.
|
||||||
import { generateSitemap } from './build/sitemap.js';
|
import { generateSitemap } from './build/sitemap.js';
|
||||||
import { logURLStats, collectBundleStats, mapBundleStatsToURLStats } from './build/stats.js';
|
import { logURLStats, collectBundleStats, mapBundleStatsToURLStats } from './build/stats.js';
|
||||||
import { getDistPath, stopTimer } from './build/util.js';
|
import { getDistPath, stopTimer } from './build/util.js';
|
||||||
import { debug, defaultLogDestination, error, info, warn, trapWarn } from './logger.js';
|
import { debug, defaultLogDestination, defaultLogLevel, error, info, warn, trapWarn } from './logger.js';
|
||||||
import { createRuntime } from './runtime.js';
|
import { createRuntime } from './runtime.js';
|
||||||
|
|
||||||
const defaultLogging: LogOptions = {
|
const defaultLogging: LogOptions = {
|
||||||
level: 'debug',
|
level: defaultLogLevel,
|
||||||
dest: defaultLogDestination,
|
dest: defaultLogDestination,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -6,14 +6,14 @@ import { green } from 'kleur/colors';
|
||||||
import http from 'http';
|
import http from 'http';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import { performance } from 'perf_hooks';
|
import { performance } from 'perf_hooks';
|
||||||
import { defaultLogDestination, debug, error, info, parseError } from './logger.js';
|
import { defaultLogDestination, defaultLogLevel, debug, error, info, parseError } from './logger.js';
|
||||||
import { createRuntime } from './runtime.js';
|
import { createRuntime } from './runtime.js';
|
||||||
import { stopTimer } from './build/util';
|
import { stopTimer } from './build/util';
|
||||||
|
|
||||||
const hostname = '127.0.0.1';
|
const hostname = '127.0.0.1';
|
||||||
|
|
||||||
const logging: LogOptions = {
|
const logging: LogOptions = {
|
||||||
level: 'debug',
|
level: defaultLogLevel,
|
||||||
dest: defaultLogDestination,
|
dest: defaultLogDestination,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import 'source-map-support/register.js';
|
import 'source-map-support/register.js';
|
||||||
import type { CompileError } from '@astrojs/parser';
|
import type { CompileError } from '@astrojs/parser';
|
||||||
import { bold, blue, red, grey, underline } from 'kleur/colors';
|
import { bold, blue, red, grey, underline, yellow } from 'kleur/colors';
|
||||||
import { Writable } from 'stream';
|
import { Writable } from 'stream';
|
||||||
import { format as utilFormat } from 'util';
|
import { format as utilFormat } from 'util';
|
||||||
import stringWidth from 'string-width';
|
import stringWidth from 'string-width';
|
||||||
|
@ -20,6 +20,8 @@ export const defaultLogDestination = new Writable({
|
||||||
if (type !== null) {
|
if (type !== null) {
|
||||||
if (event.level === 'info') {
|
if (event.level === 'info') {
|
||||||
type = bold(blue(type));
|
type = bold(blue(type));
|
||||||
|
} else if (event.level === 'warn') {
|
||||||
|
type = bold(yellow(type));
|
||||||
} else if (event.level === 'error') {
|
} else if (event.level === 'error') {
|
||||||
type = bold(red(type));
|
type = bold(red(type));
|
||||||
}
|
}
|
||||||
|
@ -166,3 +168,5 @@ function padStr(str: string, len: number) {
|
||||||
const spaces = Array.from({ length: len - strLen }, () => ' ').join('');
|
const spaces = Array.from({ length: len - strLen }, () => ' ').join('');
|
||||||
return str + spaces;
|
return str + spaces;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const defaultLogLevel: LoggerLevel = process.argv.includes('--verbose') ? 'debug' : 'info';
|
|
@ -1,9 +1,9 @@
|
||||||
import type { LogOptions } from './logger';
|
import type { LogOptions } from './logger';
|
||||||
import { clearCache } from 'snowpack';
|
import { clearCache } from 'snowpack';
|
||||||
import { defaultLogDestination, debug, error, info, parseError } from './logger.js';
|
import { defaultLogDestination, defaultLogLevel, info } from './logger.js';
|
||||||
|
|
||||||
const logging: LogOptions = {
|
const logging: LogOptions = {
|
||||||
level: 'debug',
|
level: defaultLogLevel,
|
||||||
dest: defaultLogDestination,
|
dest: defaultLogDestination,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -1,15 +1,12 @@
|
||||||
import { logger as snowpackLogger } from 'snowpack';
|
import { logger as snowpackLogger } from 'snowpack';
|
||||||
|
import { defaultLogLevel } from './logger.js';
|
||||||
function verboseLogging() {
|
|
||||||
return process.argv.includes('--verbose');
|
|
||||||
}
|
|
||||||
|
|
||||||
const onceMessages = ['Ready!', 'watching for file changes'].map((str) => new RegExp(`\\[snowpack\\](.*?)${str}`));
|
const onceMessages = ['Ready!', 'watching for file changes'].map((str) => new RegExp(`\\[snowpack\\](.*?)${str}`));
|
||||||
|
|
||||||
export function configureSnowpackLogger(logger: typeof snowpackLogger) {
|
export function configureSnowpackLogger(logger: typeof snowpackLogger) {
|
||||||
const messageCache = new Set<string>();
|
const messageCache = new Set<string>();
|
||||||
|
|
||||||
if (verboseLogging()) {
|
if (defaultLogLevel === 'debug') {
|
||||||
logger.level = 'debug';
|
logger.level = 'debug';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue