Skip to content

Instantly share code, notes, and snippets.

@SimonGivre
Created September 18, 2012 02:38
Show Gist options
  • Save SimonGivre/3740951 to your computer and use it in GitHub Desktop.
Save SimonGivre/3740951 to your computer and use it in GitHub Desktop.
JS tail server logs
var jq = document.createElement('script');
jq.src = "http://code.jquery.com/jquery-latest.min.js";
document.getElementsByTagName('head')[0].appendChild(jq);
function tail(){
$.get(window.location.href+'?'+new Date().getTime(),function(data){
var $newPre = $('<pre></pre>');
var logArray = data.split('\n');
var lineCount = logArray.length;
$newPre.append('Line count='+lineCount+'\n');
var tail = "";
var tailSize = 50;
for(var i=(lineCount-tailSize);i<lineCount;i++){
tail = tail + (logArray[i]+'\n');
}
$newPre.append(tail);
$('pre').remove();
$('body').append($newPre);
});
}
var id = setInterval(tail,1000);
console.log(id);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment