Refactor logger to output only to log file and stderr

- Removed console output for log messages, focusing on file logging.
- Added stderr fallback for log messages when log file is unavailable.
- Improved error handling for log file write failures.
This commit is contained in:
Alex Newman
2025-12-27 20:22:31 -05:00
parent 356e3acae3
commit 5f34cae636
9 changed files with 118 additions and 106 deletions
+6 -10
View File
@@ -257,21 +257,17 @@ class Logger {
const logLine = `[${timestamp}] [${levelStr}] [${componentStr}] ${correlationStr}${message}${contextStr}${dataStr}`;
// Output to console
if (level === LogLevel.ERROR) {
console.error(logLine);
} else {
console.log(logLine);
}
// Output to log file
// Output to log file ONLY (worker runs in background, console is useless)
if (this.logFilePath) {
try {
appendFileSync(this.logFilePath, logLine + '\n', 'utf8');
} catch (error) {
// If file write fails, just continue (don't crash)
console.error('[LOGGER] Failed to write to log file:', error);
// If file write fails, write to stderr as last resort
process.stderr.write(`[LOGGER] Failed to write to log file: ${error}\n`);
}
} else {
// If no log file available, write to stderr as fallback
process.stderr.write(logLine + '\n');
}
}