Add dnsmasq tail log formatting (#2878)

This commit is contained in:
DL6ER
2023-11-28 22:23:44 +01:00
committed by GitHub
2 changed files with 27 additions and 1 deletions

View File

@@ -19,6 +19,25 @@ const fadeIn = true;
// Mark new lines with a red line above them // Mark new lines with a red line above them
const markUpdates = true; const markUpdates = true;
// Format a line of the dnsmasq log
function formatLine(line) {
// Remove dnsmasq + PID
let txt = line.replaceAll(/ dnsmasq\[\d*]/g, "");
if (line.includes("denied") || line.includes("gravity blocked")) {
// Red bold text for blocked domains
txt = `<b class="log-red">${txt}</b>`;
} else if (line.includes("query[A") || line.includes("query[DHCP")) {
// Bold text for initial query lines
txt = `<b>${txt}</b>`;
} else {
// Grey text for all other lines
txt = `<span class="text-muted">${txt}</span>`;
}
return txt;
}
// Function that asks the API for new data // Function that asks the API for new data
function getData() { function getData() {
// Only update when spinner is spinning // Only update when spinner is spinning
@@ -71,9 +90,12 @@ function getData() {
} }
data.log.forEach(function (line) { data.log.forEach(function (line) {
// Format line if this is the dnsmasq log
if (GETDict.file === "dnsmasq") line.message = formatLine(line.message);
// Add new line to output // Add new line to output
$("#output").append( $("#output").append(
'<span><span style="border-left: 2px red" class="left-line">&nbsp;</span><span class="text-muted">' + '<span class="log-entry"><span class="text-muted">' +
moment(1000 * line.timestamp).format("YYYY-MM-DD HH:mm:ss.SSS") + moment(1000 * line.timestamp).format("YYYY-MM-DD HH:mm:ss.SSS") +
"</span> " + "</span> " +
line.message + line.message +

View File

@@ -1430,3 +1430,7 @@ table.dataTable tbody > tr > .selected {
margin: 0.5em 0; margin: 0.5em 0;
align-items: start; align-items: start;
} }
.log-entry {
padding-left: 0.5em;
}