Skip to content

Commit bbe1fd5

Browse files
feat(logging): auto-detect output format based on environment 🖥️
Pretty-print for human-readable output in terminals and CI, JSON for log aggregation in production (Docker/PM2/pipes). - TTY detected → pretty format - CI env var set → pretty format - Otherwise → JSON for collectors (Loki, ELK, etc.) Explicit config still overrides: `logging.prettyPrint: true|false` Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent d627811 commit bbe1fd5

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

api/utils/log.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -216,9 +216,12 @@ class LogManager {
216216
this.#prefs = loadLoggingConfig();
217217
this.#prefs.default = this.#prefs.default || 'warn';
218218
this.#deflt = this.#prefs.default || 'error';
219-
// Pretty-print enabled by default for human-readable console output
220-
// Set config.logging.prettyPrint = false for JSON output (e.g., for log aggregation)
221-
this.#prettyPrint = this.#prefs.prettyPrint !== false;
219+
// Output format determined by: explicit config > environment detection
220+
// - prettyPrint: true → always pretty (human-readable)
221+
// - prettyPrint: false → always JSON (for log aggregation)
222+
// - prettyPrint: unset → auto-detect (pretty in terminal/CI, JSON in Docker/PM2/pipes)
223+
const isInteractive = process.stdout.isTTY || !!process.env.CI;
224+
this.#prettyPrint = this.#prefs.prettyPrint ?? isInteractive;
222225

223226
// Initialize OpenTelemetry metrics if available
224227
if (metrics) {

0 commit comments

Comments
 (0)