From e94c15ea871c139f68a4e53c21ef5677d2dc93cc Mon Sep 17 00:00:00 2001 From: jnjpng Date: Thu, 12 Mar 2026 12:56:05 -0600 Subject: [PATCH] feat: colorize debug log screen output (#1365) --- src/utils/debug.ts | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/utils/debug.ts b/src/utils/debug.ts index 4d5cf29..a48998a 100644 --- a/src/utils/debug.ts +++ b/src/utils/debug.ts @@ -37,7 +37,7 @@ function getDebugFile(): string | null { } /** Print to screen (or LETTA_DEBUG_FILE). Only called when LETTA_DEBUG=1. */ -function printDebugLine(line: string): void { +function printDebugLine(line: string, level: "log" | "warn" = "log"): void { const debugFile = getDebugFile(); if (debugFile) { try { @@ -47,7 +47,11 @@ function printDebugLine(line: string): void { // Fall back to console if file write fails } } - console.log(line.trimEnd()); + const colored = + level === "warn" + ? `\x1b[38;5;167m${line.trimEnd()}\x1b[0m` // muted red + : `\x1b[38;5;179m${line.trimEnd()}\x1b[0m`; // muted golden yellow + console.log(colored); } // --------------------------------------------------------------------------- @@ -148,6 +152,7 @@ function writeDebugLine( prefix: string, message: string, args: unknown[], + level: "log" | "warn" = "log", ): void { const ts = new Date().toISOString(); const body = format(`[${prefix}] ${message}`, ...args); @@ -158,7 +163,7 @@ function writeDebugLine( // Screen output only when LETTA_DEBUG is on if (isDebugEnabled()) { - printDebugLine(line); + printDebugLine(line, level); } } @@ -187,5 +192,5 @@ export function debugWarn( message: string, ...args: unknown[] ): void { - writeDebugLine(prefix, `WARN: ${message}`, args); + writeDebugLine(prefix, `WARN: ${message}`, args, "warn"); }