improve log monitor

This commit is contained in:
Vladimir Mandic
2024-03-03 19:53:47 -05:00
parent 1b44a16a4e
commit f7ea762073
7 changed files with 59 additions and 12 deletions
+33 -7
View File
@@ -1,5 +1,20 @@
let logMonitorEl = null;
let logMonitorStatus = true;
let logWarnings = 0
let logErrors = 0
function dateToStr(ts) {
const dt = new Date(1000 * ts);
const year = dt.getFullYear();
const mo = String(dt.getMonth() + 1).padStart(2, '0');
const day = String(dt.getDate()).padStart(2, '0');
const hour = String(dt.getHours()).padStart(2, '0');
const min = String(dt.getMinutes()).padStart(2, '0');
const sec = String(dt.getSeconds()).padStart(2, '0');
const ms = String(dt.getMilliseconds()).padStart(3, '0');
const s = `${year}-${mo}-${day} ${hour}:${min}:${sec}.${ms}`;
return s
}
async function logMonitor() {
if (logMonitorStatus) setTimeout(logMonitor, opts.logmonitor_refresh_period);
@@ -24,14 +39,23 @@ async function logMonitor() {
try {
const l = JSON.parse(line);
const row = document.createElement('tr');
row.style = 'padding: 10px; margin: 0;';
row.innerHTML = `<td>${new Date(1000 * l.created).toISOString()}</td><td>${l.level}</td><td>${l.facility}</td><td>${l.module}</td><td>${l.msg}</td>`;
// row.style = 'padding: 10px; margin: 0;';
const level = `<td style="color: var(--color-${l.level.toLowerCase()})">${l.level}</td>`;
if (l.level == 'WARNING') logWarnings++;
if (l.level == 'ERROR') logErrors++;
const module = `<td style="color: var(--var(--neutral-400))">${l.module}</td>`;
row.innerHTML = `<td>${dateToStr(l.created)}</td>${level}<td>${l.facility}</td>${module}<td>${l.msg}</td>`;
logMonitorEl.appendChild(row);
} catch {}
} catch (e) {
console.log('logMonitor', e);
console.error('logMonitor line', line);
}
}
while (logMonitorEl.childElementCount > 100) logMonitorEl.removeChild(logMonitorEl.firstChild);
if (at_bottom) logMonitorEl.scrollTop = logMonitorEl.scrollHeight;
else if (lines?.length > 0) logMonitorEl.parentElement.style = 'border-bottom: 2px solid var(--highlight-color);';
document.getElementById('logWarnings').innerText = logWarnings;
document.getElementById('logErrors').innerText = logErrors;
}
}
@@ -47,14 +71,16 @@ async function initLogMonitor() {
<table id="logMonitor" style="width: 100%;">
<thead style="display: block; text-align: left; border-bottom: solid 1px var(--button-primary-border-color)">
<tr>
<th style="width: 160px">Time</th>
<th style="width: 144px">Time</th>
<th>Level</th>
<th style="width: 72px">Facility</th>
<th style="width: 124px">Module</th>
<th style="width: 0"></th>
<th style="width: 154px">Module</th>
<th>Message</th>
<th style="position: absolute; right: 7em">Warnings <span id="logWarnings">0</span></th>
<th style="position: absolute; right: 1em">Errors <span id="logErrors">0</span></th>
</tr>
</thead>
<tbody id="logMonitorData" style="white-space: nowrap; height: 10vh; width: 100vw; display: block; overflow-x: hidden; overflow-y: scroll">
<tbody id="logMonitorData" style="white-space: nowrap; height: 10vh; width: 100vw; display: block; overflow-x: hidden; overflow-y: scroll; color: var(--neutral-400)">
</tbody>
</table>
`;