I wrote a simple little script, designed to load some log file. Clearing lines and loading updates is done by double clicking on the log line to clear.
<html lang="en">
<head>
<meta charset="utf-8">
<title>🌳🐞</title>
<style>
pre {
margin: 0;
}
</style>
<script>
var chunks = [];
var last_seen_time;
var cursor = 0;
var log_dom;
var log_file = 'django.log';
if (location.search && location.search.substr(1).length > 0) {
log_file = location.search.substr(1);
}
function html_entities(str) {
return String(str).replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"');
}
function toggle_color(e) {
if (e.target.id=='logs_go_here') { return; }
if (!e.target.dataset.clicked) {
e.target.dataset.clicked = 1;
e.target.style.color = 'red';
} else {
while(e.target.previousSibling) {
var node = e.target.previousSibling;
node.parentNode.removeChild(node);
}
load_log();
}
}
function load_log() {
var xhr = new XMLHttpRequest();
xhr.onload = function(){
var html = '';
if (xhr.readyState === 4) {
if (xhr.status === 200) {
var mtime = new Date(xhr.getResponseHeader('Last-Modified'));
var lines = xhr.responseText.substr(cursor);
lines = lines.split("\n");
for (var i = 0, len = lines.length; i < len; i++) {
if (i == len - 1 && lines[i] == "") {
cursor -= 1;
break;
}
cursor += lines[i].length + 1;
html += "<pre>" + html_entities(lines[i]) + "</pre>";
}
var current_nodes = log_dom.children;
for (var i = 0, len = current_nodes.length; i < len; i++) {
if (current_nodes[i].style.color != 'red') {
current_nodes[i].style.color = '#555';
}
}
log_dom.innerHTML += html;
document.title = '🌳🐞';
} else {
document.title = '😞';
}
}
};
xhr.open("get", log_file, true);
xhr.send();
}
function refresh() {
document.title = '🔄';
load_log();
}
document.addEventListener("DOMContentLoaded", function(event) {
log_dom = document.getElementById('logs_go_here');
log_dom.addEventListener("click", toggle_color);
refresh();
});
</script>
</head>
<body>
<div id="logs_go_here">
</div>
<div style="position:fixed;right:0;top:0;width:100px;">
<span style="font-size: 100px;cursor:pointer;z-index:1000;" onClick="refresh();">🔄</span>
</div>
</body>