How can I make a log box always show the last line?

Asked

Viewed 81 times

0

hi, I have a log file of other codes that keeps updating so I made a javascript code that shows this file and is a code that keeps updating the live text on the page inside a textarea but it keeps updating and always back to the first line,ai never has to see the final part, I wonder if it’s css thing that has q stir or javascript msm.

JS Code:

var url  = "wget-log";
var textarea_id = "textarea";

setInterval(function(){

$.ajax({
url : "wget-log",
type : "POST",
success : function(data){
$(".textarea").html(data);

}

});
}, 1000); 

Log format:

     0K .......... .......... .......... .......... ..........  0%  116K 31m1s
    50K .......... .......... .......... .......... ..........  0%  454K 19m27s
   100K .......... .......... .......... .......... ..........  0% 92.1K 25m56s
   150K .......... .......... .......... .......... ..........  0%  184K 24m18s
   200K .......... .......... .......... .......... ..........  0% 44.4K 35m34s
   250K .......... .......... .......... .......... ..........  0%  620K 30m36s
   300K .......... .......... .......... .......... ..........  0% 93.5K 31m41s
   350K .......... .......... .......... .......... ..........  0% 70.0K 34m7s
   400K .......... .......... .......... .......... ..........  0% 57.5K 37m14s
   450K .......... .......... .......... .......... ..........  0% 71.1K 38m32s
   500K .......... .......... .......... .......... ..........  0%  788K 35m26s
   550K .......... .......... .......... .......... ..........  0%  553K 33m1s
   600K .......... .......... .......... .......... ..........  0% 66.5K 34m36s
   650K .......... .......... .......... .......... ..........  0% 1.29M 32m19s
   700K .......... .......... .......... .......... ..........  0%  565K 30m34s
   750K .......... .......... .......... .......... ..........  0%  652K 29m0s
   800K .......... .......... .......... .......... ..........  0% 55.8K 31m3s
   850K .......... .......... .......... .......... ..........  0% 71.7K 32m5s
   900K .......... .......... .......... .......... ..........  0%  103K 32m12s
   950K .......... .......... .......... .......... ..........  0%  101K 32m21s
  1000K .......... .......... .......... .......... ..........  0% 33.5K 35m52s

Because of this format I can never read what is really happening since the latest updates are at the end

  • Hello, the log that is sent is only one item or it always returns all lines?

1 answer

0


You can try a regular expression to capture the last line and display it.

Try this regex: \r?\n?[^\r\n]*$

Browser other questions tagged

You are not signed in. Login or sign up in order to post.