Files
openapi-clean-arch-gen/src/utils/logger.ts
didavila 79ea7dfc7e
All checks were successful
Lint / lint (pull_request) Successful in 16s
feat: enhance logging and linting functionality with detailed reports
2026-03-26 13:03:10 +01:00

61 lines
1.7 KiB
TypeScript
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import fs from 'fs-extra';
const colors = {
reset: '\x1b[0m',
bright: '\x1b[1m',
green: '\x1b[32m',
blue: '\x1b[34m',
yellow: '\x1b[33m',
red: '\x1b[31m',
cyan: '\x1b[36m'
} as const;
type Color = keyof typeof colors;
let _logFilePath: string | null = null;
/** Initialises the generation log file, overwriting any previous run. */
export function initGenerationLog(filePath: string): void {
_logFilePath = filePath;
fs.writeFileSync(filePath, `Generation log — ${new Date().toISOString()}\n${'='.repeat(60)}\n`);
}
/** Writes a detailed entry to the generation log file (not to console). */
export function logDetail(category: string, message: string): void {
if (!_logFilePath) return;
const line = `[${new Date().toISOString()}] [${category.toUpperCase().padEnd(8)}] ${message}\n`;
fs.appendFileSync(_logFilePath, line);
}
/** Prints a console message with the given ANSI colour. */
export function log(message: string, color: Color = 'reset'): void {
console.log(`${colors[color]}${message}${colors.reset}`);
}
/** Prints a success message (green). */
export function logSuccess(message: string): void {
log(`${message}`, 'green');
}
/** Prints an informational message (blue). */
export function logInfo(message: string): void {
log(` ${message}`, 'blue');
}
/** Prints a warning message (yellow). */
export function logWarning(message: string): void {
log(`⚠️ ${message}`, 'yellow');
}
/** Prints an error message (red). */
export function logError(message: string): void {
log(`${message}`, 'red');
}
/** Prints a step/stage header (cyan). */
export function logStep(message: string): void {
log(`\n🚀 ${message}`, 'cyan');
}
export { colors };