7

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

Community
  • 1
  • 1
DaveBurns
  • 2,036
  • 2
  • 27
  • 37
  • Have a look at http://www.coldfusionjedi.com/index.cfm/2009/4/12/Using-ColdFusion-to-get-the-end-of-a-file - you only need to add a refresh each minute or so.. – da_didi May 31 '11 at 15:28
  • You can try HTML5's Server-Sent Events if you want good streaming solution. – Henry May 31 '11 at 17:13

4 Answers4

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");
?>
Owen
  • 630
  • 6
  • 21
  • I tried this on Mac OS X on /var/log/syslog and nothing appears in the browser window until I stop the php server. Any idea how to flush the output periodically? – Sridhar Sarnobat Apr 08 '14 at 18:19
0

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

Habibutsu
  • 592
  • 1
  • 8
  • 20
0

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.

Community
  • 1
  • 1
orangepips
  • 9,891
  • 6
  • 33
  • 57
  • Thanks, orangepips. There are the usual issues with log files such as them being large. I don't want to repeatedly send the same 1MB of data just to get the latest 10 lines. I'm now thinking of something purely client-side using AJAX and HTTP's HEAD request to look at the Content-Length. If that has changed from the previous value, do a GET using the HTTP Range field to only get the updated data to append to the DOM. Seems like something that should already exist so I'm Googling around... – DaveBurns May 31 '11 at 15:51
  • You're not sending the same data repeatedly because the file reference is only created once and persisted into the application scope. So every refresh only shows newly added lines. – orangepips May 31 '11 at 16:18
  • Ah, of course. How do you think the above will handle log roll-over? – DaveBurns May 31 '11 at 19:07
  • @DaveBurns: it won't, you'll need to write that algorithm. Presumably you'll know what time or file size the log rolls over. So `fileClose()` the current reference and create anew. Also if your CF server restarts you may need to think about maintaining a line pointer in that situation when in comes back up and iterating forward to where you need to be in that situation. – orangepips May 31 '11 at 19:14
-1

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.

bpanulla
  • 2,988
  • 1
  • 19
  • 23
  • 1
    It crossed my mind. Logging to databases is one of those things people love or hate - somehow it gets religious. I'm one of those who feels like it's too heavyweight. Good topic for discussion though - thanks. – DaveBurns Jun 01 '11 at 19:17