mirror of
https://github.com/mohamadihsan/topuponline.git
synced 2026-12-05 10:46:28 +00:00
Reserve terminal log colors for warnings and errors
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user