From 0ab70366202b920c774c5f9c4e5c848246c8bb6c Mon Sep 17 00:00:00 2001 From: DL6ER Date: Fri, 1 Dec 2023 15:02:22 +0100 Subject: [PATCH] Show log priority Signed-off-by: DL6ER --- scripts/pi-hole/js/taillog.js | 41 +++++++++++++++++++++++++++++++---- 1 file changed, 37 insertions(+), 4 deletions(-) diff --git a/scripts/pi-hole/js/taillog.js b/scripts/pi-hole/js/taillog.js index 65d1858f..ad407aff 100644 --- a/scripts/pi-hole/js/taillog.js +++ b/scripts/pi-hole/js/taillog.js @@ -20,7 +20,7 @@ const fadeIn = true; const markUpdates = true; // Format a line of the dnsmasq log -function formatLine(line) { +function formatDnsmasq(line) { // Remove dnsmasq + PID let txt = line.replaceAll(/ dnsmasq\[\d*]/g, ""); @@ -38,6 +38,36 @@ function formatLine(line) { return txt; } +function formatFTL(line, prio) { + // Colorize priority + let prioClass = ""; + switch (prio) { + case "INFO": { + prioClass = "text-success"; + break; + } + + case "WARNING": { + prioClass = "text-warning"; + break; + } + + case "ERR": + case "EMERG": + case "ALERT": + case "CRIT": { + prioClass = "text-danger"; + break; + } + + default: + prioClass = prio.startsWith("DEBUG") ? "text-info" : "text-muted"; + } + + // Return formatted line + return `${utils.escapeHtml(prio)} ${line}`; +} + // Function that asks the API for new data function getData() { // Only update when spinner is spinning @@ -90,8 +120,11 @@ function getData() { } data.log.forEach(function (line) { - // Format line if this is the dnsmasq log - if (GETDict.file === "dnsmasq") line.message = formatLine(line.message); + // Escape HTML + line.message = utils.escapeHtml(line.message); + // Format line if applicable + if (GETDict.file === "dnsmasq") line.message = formatDnsmasq(line.message); + else if (GETDict.file === "ftl") line.message = formatFTL(line.message, line.prio); // Add new line to output $("#output").append( @@ -99,7 +132,7 @@ function getData() { moment(1000 * line.timestamp).format("YYYY-MM-DD HH:mm:ss.SSS") + " " + line.message + - "
" + "
" ); if (fadeIn) { //$(".left-line:last").fadeOut(2000);