Skip to content

Commit 310b2f0

Browse files
fix: configure logger using options from cli
1 parent e1f43a2 commit 310b2f0

File tree

2 files changed

+14
-15
lines changed

2 files changed

+14
-15
lines changed

src/cli.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import { Command } from "commander";
33
import fs from "fs";
44
import chalk from "chalk";
5-
import { logger, OUTPUT_LEVELS, configureLogger } from "./lib/logger.js";
5+
import { Logger, OUTPUT_LEVELS } from "./lib/logger.js";
66
import {
77
validateInputs,
88
getUrlList,
@@ -38,7 +38,6 @@ program
3838
.parse(process.argv);
3939

4040
const options = program.opts();
41-
configureLogger(options);
4241

4342
// Validate mutually exclusive flags
4443
if (options.verbose && options.silent) {
@@ -48,6 +47,9 @@ if (options.verbose && options.silent) {
4847
process.exit(1);
4948
}
5049

50+
const logger = new Logger();
51+
logger.configure(options);
52+
5153
(async () => {
5254
const startTime = Date.now();
5355
logger.verbose(`Starting frontend-performance-analyzer v${version}`);
@@ -58,12 +60,12 @@ if (options.verbose && options.silent) {
5860
logger.verbose(`Options: ${JSON.stringify(options, null, 2)}`);
5961

6062
// Validate inputs before processing
61-
validateInputs(options);
63+
validateInputs(options, logger);
6264

63-
const urls = getUrlList(options);
65+
const urls = getUrlList(options, logger);
6466

6567
// Check URL accessibility and get only accessible ones
66-
const accessibleUrls = await validateUrlAccessibility(urls);
68+
const accessibleUrls = await validateUrlAccessibility(urls, logger);
6769
const allResults = []; // Store all results for batch JSON export
6870

6971
logger.info(chalk.blue.bold("🚀 Starting Lighthouse analysis...\n"));

src/lib/url-utils.js

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import fs from "fs";
22
import path from "path";
33
import chalk from "chalk";
4-
import { logger, outputLevel, OUTPUT_LEVELS } from "./logger.js";
4+
import { OUTPUT_LEVELS } from "./logger.js";
55

66
export function isValidUrl(string) {
77
try {
@@ -12,7 +12,7 @@ export function isValidUrl(string) {
1212
}
1313
}
1414

15-
export function validateInputs(options) {
15+
export function validateInputs(options, logger) {
1616
logger.verbose("Validating input options...");
1717

1818
// Check if at least one URL source is provided
@@ -59,7 +59,7 @@ export function validateInputs(options) {
5959
logger.verbose("Input validation completed successfully");
6060
}
6161

62-
export function getUrlList(options) {
62+
export function getUrlList(options, logger) {
6363
logger.verbose("Extracting URL list from options...");
6464
let urls = [];
6565

@@ -109,7 +109,7 @@ export function getUrlList(options) {
109109
return urls;
110110
}
111111

112-
async function checkUrlAccessibility(url) {
112+
async function checkUrlAccessibility(url, logger) {
113113
logger.verbose(`Checking accessibility for: ${url}`);
114114
try {
115115
const startTime = Date.now();
@@ -129,7 +129,7 @@ async function checkUrlAccessibility(url) {
129129
}
130130
}
131131

132-
export async function validateUrlAccessibility(urls) {
132+
export async function validateUrlAccessibility(urls, logger) {
133133
logger.info(chalk.blue("🔍 Checking URL accessibility..."));
134134
logger.verbose(`Starting accessibility check for ${urls.length} URLs`);
135135

@@ -139,13 +139,10 @@ export async function validateUrlAccessibility(urls) {
139139
for (let i = 0; i < urls.length; i++) {
140140
const url = urls[i];
141141
logger.verbose(`Checking URL ${i + 1}/${urls.length}: ${url}`);
142-
143-
if (outputLevel >= OUTPUT_LEVELS.NORMAL) {
144-
process.stdout.write(` Checking ${url}... `);
145-
}
142+
logger.info(` Checking ${url}... `, OUTPUT_LEVELS.NORMAL);
146143

147144
const startTime = Date.now();
148-
const isAccessible = await checkUrlAccessibility(url);
145+
const isAccessible = await checkUrlAccessibility(url, logger);
149146
const duration = Date.now() - startTime;
150147

151148
if (isAccessible) {

0 commit comments

Comments
 (0)