From 347e604ac066db316e53263b67f280c46989ccc4 Mon Sep 17 00:00:00 2001 From: Mohamad Ihsan Date: Wed, 25 Nov 2026 05:37:45 +0700 Subject: [PATCH] Reserve terminal log colors for warnings and errors --- application/helpers/terminal-log-color.js | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/application/helpers/terminal-log-color.js b/application/helpers/terminal-log-color.js index 69ab899..89ba303 100644 --- a/application/helpers/terminal-log-color.js +++ b/application/helpers/terminal-log-color.js @@ -1,13 +1,11 @@ const RED = '\x1b[31m'; const YELLOW = '\x1b[33m'; -const GREEN = '\x1b[32m'; const RESET = '\x1b[0m'; function colorForResponseCode(code) { - if (/^(0[0-4]|2\d{2})$/.test(code)) return GREEN; - if (code === '423') return RED; - if (/^4\d{2}$/.test(code) || code === '5003') return YELLOW; - if (/^5\d{2,3}$/.test(code)) return RED; + // Kode sukses dan informasi tetap polos agar warna hanya menandai perhatian. + if (code === '423' || /^5\d{2}$/.test(code) || /^500[124]$/.test(code)) return RED; + if (code === '5003' || /^4\d{2}$/.test(code)) return YELLOW; } function colorTerminalLine(line) { @@ -22,11 +20,11 @@ function colorTerminalLine(line) { let color; if (record.event === 'http_response') { - // Kode aplikasi tetap bermakna saat API mengembalikan HTTP 200. + // Status HTTP server lebih utama; kode aplikasi membedakan hasil saat HTTP 200. if (record.http_status >= 500) color = RED; else if (record.http_status >= 400) color = YELLOW; else color = colorForResponseCode(record.status_code); - } else if (record.level !== 'fatal' && record.level !== 'error' && typeof record.message === 'string') { + } else if (typeof record.message === 'string') { const [, code] = record.message.match(/(?:^|\s)code=(\d{2,4})(?=\s|$)/) || []; color = colorForResponseCode(code); }