feat(mod_logger): add centralized TsBuildLogger and replace ad-hoc console output with structured, colored logging

This commit is contained in:
2026-03-06 07:32:35 +00:00
parent 83e0e9b5dd
commit b3d1982170
8 changed files with 169 additions and 137 deletions

View File

@@ -0,0 +1,72 @@
/**
* Centralized console output for tsbuild.
*
* Visual hierarchy (4 levels):
* HEADER — top-level section start (emoji + bold text + separator line)
* STEP — major action within a section (emoji + text, no indent)
* DETAIL — supplementary info under a step (3-space indent + emoji + text)
* SUCCESS/ERROR/WARN — outcome indicators (emoji + text, no indent)
*/
export class TsBuildLogger {
static readonly c = {
reset: '\x1b[0m',
bold: '\x1b[1m',
dim: '\x1b[2m',
red: '\x1b[31m',
green: '\x1b[32m',
yellow: '\x1b[33m',
cyan: '\x1b[36m',
white: '\x1b[37m',
brightRed: '\x1b[91m',
brightGreen: '\x1b[92m',
brightYellow: '\x1b[93m',
};
static readonly SEPARATOR_WIDTH = 70;
static separator(char = '─'): string {
return char.repeat(this.SEPARATOR_WIDTH);
}
/** Level 1: Section header. Blank line before, separator after. */
static header(emoji: string, text: string): void {
console.log('');
console.log(`${emoji} ${this.c.bold}${text}${this.c.reset}`);
console.log(this.c.dim + this.separator() + this.c.reset);
}
/** Level 2: Step within a section. No indent. */
static step(emoji: string, text: string): void {
console.log(`${emoji} ${text}`);
}
/** Level 3: Detail under a step. 3-space indent. */
static detail(emoji: string, text: string): void {
console.log(` ${emoji} ${text}`);
}
/** Outcome: success */
static success(text: string): void {
console.log(`${this.c.green}${text}${this.c.reset}`);
}
/** Outcome: error (goes to stderr) */
static error(text: string): void {
console.error(`${this.c.red}${text}${this.c.reset}`);
}
/** Outcome: warning */
static warn(text: string): void {
console.log(`${this.c.yellow}⚠️ ${text}${this.c.reset}`);
}
/** Plain indented line (for code snippets, list items, etc.) */
static indent(text: string, level = 1): void {
console.log(' '.repeat(level) + text);
}
/** Blank line */
static blank(): void {
console.log('');
}
}

1
ts/mod_logger/index.ts Normal file
View File

@@ -0,0 +1 @@
export * from './classes.logger.js';