Skip to content

Commit

Permalink
Improve log rendering
Browse files Browse the repository at this point in the history
Use pre-compiled regex and define colors for debug and critical alerts
as well.
  • Loading branch information
agners committed Oct 3, 2024
1 parent 5109754 commit c9a8282
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
9 changes: 6 additions & 3 deletions rootfs/usr/share/www/static/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,10 @@ function testAvailable() {
}, scheduleTry);
}

var errorCheck = /^[\d -:]+ERROR(.*)/gm
var errorCheck = /^[\d -:]+(ERROR|CRITICAL)(.*)/gm

const regexRemoveTimestamp = /^[\[\d \-:.\]]*/gm
const regexColorLines = /^(DEBUG|INFO|WARNING|ERROR|CRITICAL)\s\(\w+\)\s(.*)\n/gm

function fetchLogs() {
fetch("/observer/logs").then(function (res) {
Expand All @@ -87,8 +90,8 @@ function fetchLogs() {
}
var scrolledDown = logElement.scrollTop + logElement.clientHeight === logElement.scrollHeight;
logElement.innerHTML = text
.replace(/^[\[\d \-:.\]]*/gm, "")
.replace(/^(INFO|WARNING|ERROR)\s\(\w+\)\s(.*)\n/gm, "<span class='$1'>$2</span>\n")
.replace(regexRemoveTimestamp, "")
.replace(regexColorLines, "<span class='$1'>$2</span>\n")
if (scrolledDown) {
// Scroll content down if it was already scrolled down
logElement.scrollTop = logElement.scrollHeight;
Expand Down
8 changes: 6 additions & 2 deletions rootfs/usr/share/www/static/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -348,11 +348,15 @@ pre:empty {
display: none;
}

pre .INFO {
pre .DEBUG {
color: #039be5;
}

pre .ERROR {
pre .INFO {
color: #43a047;
}

pre .ERROR, pre .CRITICAL {
color: #db4437;
}

Expand Down

0 comments on commit c9a8282

Please sign in to comment.