Skip to content

Instantly share code, notes, and snippets.

@camous
Last active April 5, 2017 20:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save camous/7456d36f328684afe9a890b4ec9b091c to your computer and use it in GitHub Desktop.
Save camous/7456d36f328684afe9a890b4ec9b091c to your computer and use it in GitHub Desktop.
create infinite console for azure stream with limited memory leaks
var count = 0;
var consoleMaxLines = 0;
function writeLog(text){
var div = document.getElementById("result");
var datetime = moment.utc(text,'YYYY-MM-DDTHH:mm:ss');
if(datetime.isValid()){
text = text.replace(datetime.format('YYYY-MM-DDTHH:mm:ss'),datetime.local().format('HH:mm:ss'));
}
if($("#l1").position() === undefined || $("#l1").position().top >= 0 && consoleMaxLines==0){
count++;
div.innerHTML += '<div id="l' + count.toString() + '">' + text + '</div>';
} else {
if(consoleMaxLines==0){
consoleMaxLines = document.getElementById("result").children.length;
}
for(var i=1;i<consoleMaxLines;i++){
$("#l" + i.toString()).html($("#l" + (i+1).toString()).html());
}
$("#l" + consoleMaxLines.toString()).html(text);
}
div.scrollTop = div.scrollHeight;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment