Tail a text file on a web server via HTTP

試著忘記壹切 提交于 2019-12-07 03:25:21

问题


Looking for input on how to solve the following problem. My ColdFusion 9 app has a simple logger that writes text to a file. On my dev machine, the file is local so I can use either 'tail -f' or CFB's TailView to watch it. I'd like a tool to watch it when it's deployed on the production server. The catch: production is at a shared CF hosting provider which doesn't allow RDS file access or a directory-watcher gateway. I'm wondering about a page with a meta refresh tag or if I want to get more fancy, something AJAXy to the same effect. Thoughts? Any tools that already exist for this?

I may experiment with this but am hoping there is something out there "more complete" : following a log file over http


回答1:


You can you the following PHP script:

<?php
header("Content-Type: text/plain");
set_time_limit(0);
passthru("tail -F -n +0 log.txt");
?>



回答2:


The following psuedo-code is inspired by this Java solution and has not been tested at all:

if (NOT structKeyExists(application, "log") {
    application.log = fileOpen('log.txt', 'read')
}

while(NOT FileisEOF(application.log))  {
    writeOutput(fileReadLine(application.log) & "<br/>");
}

Put that on a page with a meta refresh and I think you are probably in business.




回答3:


I create the following bash script for my use case (tail.sh)

It with using 'lynx' get list of files from which get filesize that needed, and in infinity loop trying to get part of file




回答4:


I know it's pretty old school, but have you considered logging to a database? If you timestamp the log entries in the table you could use HTTP Caching headers to communicate to the server what new data you should see.



来源:https://stackoverflow.com/questions/6189549/tail-a-text-file-on-a-web-server-via-http

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!