Skip to content

Commit 6ebe22a

Browse files
authored
Improve log rendering (#126)
Use pre-compiled regex and define colors for debug and critical alerts as well.
1 parent d5e21e3 commit 6ebe22a

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

rootfs/usr/share/www/static/scripts.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,10 @@ function testAvailable() {
7070
}, scheduleTry);
7171
}
7272

73-
var errorCheck = /^[\d -:]+ERROR(.*)/gm
73+
var errorCheck = /^[\d -:]+(ERROR|CRITICAL)(.*)/gm
74+
75+
const regexRemoveTimestamp = /^[\[\d \-:.\]]*/gm
76+
const regexColorLines = /^(DEBUG|INFO|WARNING|ERROR|CRITICAL)\s\(\w+\)\s(.*)\n/gm
7477

7578
function fetchLogs() {
7679
fetch("/observer/logs").then(function (res) {
@@ -87,8 +90,8 @@ function fetchLogs() {
8790
}
8891
var scrolledDown = logElement.scrollTop + logElement.clientHeight === logElement.scrollHeight;
8992
logElement.innerHTML = text
90-
.replace(/^[\[\d \-:.\]]*/gm, "")
91-
.replace(/^(INFO|WARNING|ERROR)\s\(\w+\)\s(.*)\n/gm, "<span class='$1'>$2</span>\n")
93+
.replace(regexRemoveTimestamp, "")
94+
.replace(regexColorLines, "<span class='$1'>$2</span>\n")
9295
if (scrolledDown) {
9396
// Scroll content down if it was already scrolled down
9497
logElement.scrollTop = logElement.scrollHeight;

rootfs/usr/share/www/static/styles.css

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -348,11 +348,15 @@ pre:empty {
348348
display: none;
349349
}
350350

351-
pre .INFO {
351+
pre .DEBUG {
352352
color: #039be5;
353353
}
354354

355-
pre .ERROR {
355+
pre .INFO {
356+
color: #43a047;
357+
}
358+
359+
pre .ERROR, pre .CRITICAL {
356360
color: #db4437;
357361
}
358362

0 commit comments

Comments
 (0)