diff --git a/docs/configuration.md b/docs/configuration.md index 109682962..a4e5b9e10 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -49,7 +49,6 @@ If set, CLAWDIS derives defaults (only when you haven’t set them explicitly): - Console output can be tuned separately via: - `logging.consoleLevel` (defaults to `info`, bumps to `debug` when `--verbose`) - `logging.consoleStyle` (`pretty` | `compact` | `json`) - - `logging.consoleColor` (`auto` | `always` | `never`) ```json5 { @@ -57,8 +56,7 @@ If set, CLAWDIS derives defaults (only when you haven’t set them explicitly): level: "info", file: "/tmp/clawdis/clawdis.log", consoleLevel: "info", - consoleStyle: "pretty", - consoleColor: "auto" + consoleStyle: "pretty" } } ``` diff --git a/docs/logging.md b/docs/logging.md index 7997b3faf..cb8731aa9 100644 --- a/docs/logging.md +++ b/docs/logging.md @@ -75,7 +75,7 @@ Behavior: - **Subsystem prefixes** on every line (e.g. `[gateway]`, `[canvas]`, `[tailscale]`) - **Subsystem colors** (stable per subsystem) plus level coloring -- **Color modes** (`logging.consoleColor`: `auto`/`always`/`never`; `auto` honors `NO_COLOR` and TTY) +- **Color only when TTY** (`process.stdout.isTTY`/`process.stderr.isTTY`), respects `NO_COLOR` - **Sub-loggers by subsystem** (auto prefix + structured field `{ subsystem }`) - **`logRaw()`** for QR/UX output (no prefix, no formatting) - **Console styles** (e.g. `pretty | compact | json`) diff --git a/src/config/config.ts b/src/config/config.ts index 5371c8d9f..9f0bb55ea 100644 --- a/src/config/config.ts +++ b/src/config/config.ts @@ -29,7 +29,6 @@ export type LoggingConfig = { | "debug" | "trace"; consoleStyle?: "pretty" | "compact" | "json"; - consoleColor?: "auto" | "always" | "never"; }; export type WebReconnectConfig = { @@ -270,9 +269,6 @@ const ClawdisSchema = z.object({ consoleStyle: z .union([z.literal("pretty"), z.literal("compact"), z.literal("json")]) .optional(), - consoleColor: z - .union([z.literal("auto"), z.literal("always"), z.literal("never")]) - .optional(), }) .optional(), browser: z diff --git a/src/logging.ts b/src/logging.ts index 5a671e564..83ba62af0 100644 --- a/src/logging.ts +++ b/src/logging.ts @@ -34,7 +34,6 @@ export type LoggerSettings = { file?: string; consoleLevel?: Level; consoleStyle?: ConsoleStyle; - consoleColor?: ConsoleColor; }; type LogObj = { date?: Date } & Record; @@ -46,11 +45,9 @@ type ResolvedSettings = { export type LoggerResolvedSettings = ResolvedSettings; export type ConsoleStyle = "pretty" | "compact" | "json"; -export type ConsoleColor = "auto" | "always" | "never"; type ConsoleSettings = { level: Level; style: ConsoleStyle; - color: ConsoleColor; }; export type ConsoleLoggerSettings = ConsoleSettings; @@ -90,8 +87,7 @@ function resolveConsoleSettings(): ConsoleSettings { overrideSettings ?? loadConfig().logging; const level = normalizeConsoleLevel(cfg?.consoleLevel); const style = normalizeConsoleStyle(cfg?.consoleStyle); - const color = normalizeConsoleColor(cfg?.consoleColor); - return { level, style, color }; + return { level, style }; } function settingsChanged(a: ResolvedSettings | null, b: ResolvedSettings) { @@ -104,7 +100,7 @@ function consoleSettingsChanged( b: ConsoleSettings, ) { if (!a) return true; - return a.level !== b.level || a.style !== b.style || a.color !== b.color; + return a.level !== b.level || a.style !== b.style; } function levelToMinLevel(level: Level): number { @@ -137,13 +133,6 @@ function normalizeConsoleStyle(style?: string): ConsoleStyle { return "pretty"; } -function normalizeConsoleColor(color?: string): ConsoleColor { - if (color === "auto" || color === "always" || color === "never") { - return color; - } - return "auto"; -} - function buildLogger(settings: ResolvedSettings): TsLogger { fs.mkdirSync(path.dirname(settings.file), { recursive: true }); // Clean up stale rolling logs when using a dated log filename. @@ -350,14 +339,10 @@ function shouldLogToConsole(level: Level, settings: ConsoleSettings): boolean { return current <= min; } -function getColorForConsole(mode: ConsoleColor): Chalk { - if (mode === "never") return new Chalk({ level: 0 }); - if (mode === "always") return new Chalk({ level: 1 }); - const supports = - process.stdout.isTTY && - !process.env.NO_COLOR && - Boolean(chalk.supportsColor); - return supports ? chalk : new Chalk({ level: 0 }); +function getColorForConsole(): Chalk { + if (process.env.NO_COLOR) return new Chalk({ level: 0 }); + const hasTty = Boolean(process.stdout.isTTY || process.stderr.isTTY); + return hasTty ? new Chalk({ level: 1 }) : new Chalk({ level: 0 }); } const SUBSYSTEM_COLORS = [ @@ -384,7 +369,6 @@ function formatConsoleLine(opts: { subsystem: string; message: string; style: ConsoleStyle; - colorMode: ConsoleColor; meta?: Record; }): string { if (opts.style === "json") { @@ -396,7 +380,7 @@ function formatConsoleLine(opts: { ...opts.meta, }); } - const color = getColorForConsole(opts.colorMode); + const color = getColorForConsole(); const prefix = `[${opts.subsystem}]`; const prefixColor = pickSubsystemColor(color, opts.subsystem); const levelColor = @@ -455,7 +439,6 @@ export function createSubsystemLogger(subsystem: string): SubsystemLogger { subsystem, message, style: consoleSettings.style, - colorMode: consoleSettings.color, meta, }); writeConsoleLine(level, line);