尾巴-f通过javascript/jquery实时日志 [英] Tail -f realtime log via javascript / jquery

查看:89
本文介绍了尾巴-f通过javascript/jquery实时日志的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试获取Real tail -f类型的查看器.

i was trying to get a Real tail -f type of viewer.

http://commavee.com/2007/04/13/ajax-logfile-tailer-viewer/(我让它完成了一些工作,但实际上并没有缓冲它)每2秒重写一次-20尾部,而不是真正地缓冲并使其可滚动(需要构建一些东西)最终也可以保存文件,但是稍后再来),如果我尝试使用tail -f命令,该命令将始终执行且不会停止

http://commavee.com/2007/04/13/ajax-logfile-tailer-viewer/ ( i got this to semi work But its not really buffering it) its rewriting the tail -20 every 2 seconds and not really Buffering it and making it scrollable (need to build something to eventually save the file as well but thats later) and if i try a tail -f the command will always execute and not stop

我是否需要考虑某种类型的暗淡*(我尝试使用正在使用的ping工具,并且经过数天的研究后在php.ini中设置了output_buffering = off,所以没有运气)*

Do i need to consider some type of obflush *(i tried that with a ping tool i was working on and NO LUCK after days of research output_buffering=off was set in the php.ini)*

<?
// logtail.php
$cmd = "tail -20 /usr/local/bin/logs/outages.log";
exec("$cmd 2>&1", $output);
foreach($output as $outputline) {
 echo ("$outputline\n");
}
?>

这是LOGTAIL.JS

THIS IS LOGTAIL.JS

function getLog(timer) {
  var url = "logtail.php";
  request1.open("GET", url, true);
  request1.onreadystatechange = updatePage;
  request1.send(null);
  startTail(timer);
}

function startTail(timer) {
  if (timer == "stop") {
    stopTail();
  } else {
    t= setTimeout("getLog()",1000);
  }
}

function stopTail() {
  clearTimeout(t);
  var pause = "The log viewer has been paused. To begin viewing again, click the Start Viewer button.\r\n\r\n";
  logDiv = document.getElementById("log");
  var newNode=document.createTextNode(pause);
  logDiv.replaceChild(newNode,logDiv.childNodes[0]);
}

function updatePage() {
  if (request1.readyState == 4) {
    if (request1.status == 200) {
      var currentLogValue = request1.responseText.split("\n");
      eval(currentLogValue);
      logDiv = document.getElementById("log");
      logDiv.scrollTop = logDiv.scrollHeight;
      var logLine = ' ';
      for (i=0; i < currentLogValue.length - 1; i++) {
        logLine += currentLogValue[i] + "<br/>\n";
      }
      logDiv.innerHTML=logLine;
      //} else
      //alert("Error! Request status is " + request1.status);
    }
  }
}

推荐答案

您可以采用稍微不同的方法,并使用Comet将消息从tail推送到浏览器.这里有一个涵盖PHP/Comet的好答案:在PHP中使用彗星吗?

You could take a slightly different approach and use Comet to push messages from tail to the browser. There's a good answer covering PHP/Comet here: Using comet with PHP?

这篇关于尾巴-f通过javascript/jquery实时日志的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆