Monitoring (i.e. loading updates) to log files 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.

&lt;html lang="en"&gt;
&lt;head&gt;
    &lt;meta charset="utf-8"&gt;
    &lt;title&gt;&lt;/title&gt;
    &lt;style&gt;
    pre {
      margin: 0;
    }
    &lt;/style&gt;
    &lt;script&gt;
    var chunks = [];
    var last_seen_time;
    var cursor = 0;
    var log_dom;

    var log_file = 'django.log';
    if (location.search &amp;&amp; location.search.substr(1).length &gt; 0) {
        log_file = location.search.substr(1);
    }

    function html_entities(str) {
        return String(str).replace(/&amp;/g, '&amp;amp;').replace(/&lt;/g, '&amp;lt;').replace(/&gt;/g, '&amp;gt;').replace(/"/g, '&amp;quot;');
    }

    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 &lt; len; i++) {
                    if (i == len - 1 &amp;&amp; lines[i] == "") {
                        cursor -= 1;
                        break;
                    }
                    cursor += lines[i].length + 1;
                    html += "&lt;pre&gt;" + html_entities(lines[i]) + "&lt;/pre&gt;";
                 }
                 var current_nodes = log_dom.children;
                 for (var i = 0, len = current_nodes.length; i &lt; 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();
    });
    &lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;
    &lt;div id="logs_go_here"&gt;
    &lt;/div&gt;
    &lt;div style="position:fixed;right:0;top:0;width:100px;"&gt;
        &lt;span style="font-size: 100px;cursor:pointer;z-index:1000;" onClick="refresh();"&gt;&lt;/span&gt;
    &lt;/div&gt;
&lt;/body&gt;
Looking at your code, it appears to be a django log. I'm not sure why you are reading logs with a webpage when you can always read them using the terminal. cat, grep, tailf and a few other commands would be your friends in this case.

As @Flambino mentioned, direct access to the log is a problem. If you are going to pursue this method, you should at least have the server side validate your access. You could use a login system, and if the user isn't logged in, you can simply throw a 403 (Forbidden) as the result of the AJAX. Otherwise, return the log contents.

Now back to the code. First off, you could wrap everything in a closure. That way, nothing is modifiable from the global scope. That prevents naming collisions and all that. At least your code is protected from other code that may reside in your page.

;(function(){

  // all your code here

}());


Next, you can use an AJAX library to abstract out your XHR code. That way, you don't have to deal with all the intricacies of XHR. A good minimum that I use, which is also forward-compatible, is using a Promise and fetch polyfill. Promise is needed for fetch to work. It's just under 20kb when minified. Rather big but keeps you sane.

fetch(url).then(function(response){
  // This is a required intermediate parsing step for fetch
  return response.text();
}).then(function(responseText){
  // Do what needs to be done with the log
}).catch(function(error){
  // Do what needs to be done during error
});


Another suggestion is to use a &lt;textarea&gt; instead of a &lt;div&gt; as your log output. That way, you don't have to deal with formatting, collapsing of tabs, escaping of characters. You can always set it to readonly to prevent editing, and modify scrollTop on update if ever you always want the bottom to be visible.

Sever logs can be huge and will have impact on your fetching operation. This happens especially if your team is using the logger extensively for easy debugging. I suggest you have some server-side logic to paginate your results and not just dump everything into the page.

I noticed your funny little characters for the title bar. While they are fun, not all computers might have those glyphs built in. On my rig, this character () doesn't appear, just a box with a question mark (or just a box on others). You might want to consider being creative in the ascii range of characters and not totally rely on these non-ascii ones. For example, this sequence -\|/- for a rotating bar. 

On a side note, it appears as though you're trying to achieve something similar to what Scalyr does - a web-based log monitoring and search.