refactor(logging): Centralize console logging with debugLogger (#11590)

This commit is contained in:
Abhi
2025-10-21 16:35:22 -04:00
committed by GitHub
parent f5e07d94bd
commit b364f37655
72 changed files with 345 additions and 289 deletions

View File

@@ -7,6 +7,7 @@
import { execSync } from 'node:child_process';
import os from 'node:os';
import { detect as chardetDetect } from 'chardet';
import { debugLogger } from './debugLogger.js';
// Cache for system encoding to avoid repeated detection
// Use undefined to indicate "not yet checked" vs null meaning "checked but failed"
@@ -66,7 +67,7 @@ export function getSystemEncoding(): string | null {
`Unable to parse Windows code page from 'chcp' output "${output.trim()}". `,
);
} catch (error) {
console.warn(
debugLogger.warn(
`Failed to get Windows code page using 'chcp' command: ${error instanceof Error ? error.message : String(error)}. ` +
`Will attempt to detect encoding from command output instead.`,
);
@@ -88,7 +89,7 @@ export function getSystemEncoding(): string | null {
.toString()
.trim();
} catch (_e) {
console.warn('Failed to get locale charmap.');
debugLogger.warn('Failed to get locale charmap.');
return null;
}
}
@@ -141,7 +142,7 @@ export function windowsCodePageToEncoding(cp: number): string | null {
return map[cp];
}
console.warn(`Unable to determine encoding for windows code page ${cp}.`);
debugLogger.warn(`Unable to determine encoding for windows code page ${cp}.`);
return null; // Return null if no mapping found
}
@@ -159,7 +160,7 @@ export function detectEncodingFromBuffer(buffer: Buffer): string | null {
return detected.toLowerCase();
}
} catch (error) {
console.warn('Failed to detect encoding with chardet:', error);
debugLogger.warn('Failed to detect encoding with chardet:', error);
}
return null;