Tail -f log on web browser?

Hello

does exist something like this http://www.logtail.org
(tail -f log on web browser) which can work only with php/ajax ?

Thank you

Wow, that has to be the least documented project I’ve ever seen.

Not one place does it actually say what it does.

Says on the front page…

“logtail is a logfile download and tailing application. It uses AJAX to update the tail-windows. The AJAX approach transfers only the added lines from a logfile over the wire.”

in a *nix environment tail is a commonly known command that echos the end of a file. Number of lines it echoes is adjustable, default is 5 if I’m not too wrong. It is mostly used to read log files, as these can be thousands of lines long. If you just want the newest entries, this is how you do it

ok, back on topic

graziano68, I’m not sure what you’re asking, but yes, I can see how this would be done :slight_smile:

Using the php exec command you execute the tail command on the log file, take the output and stick it into a json object and use javascript to load that into a website. Quite simple actually. It will be the log file on the website though, not a local log on your computer

You can do it yourself. Just open the target file, seek to the end, record the pointer’s current position, and keep it (and update it) with every subsequent Ajax request.

Well , I can do this

>
Using the php exec command you execute the tail command on the log file,
>

while I am really lost at this step , since very few experience with javascripts/ajax.

>
take the output and stick it into a json object and use javascript to load that into a website. Quite simple actually. It will be the log file on the website though, not a local log on your computer
>

Any help to realize this step please ?
( I found this http://commavee.com/2007/04/13/ajax-logfile-tailer-viewer/ , which is exactly what I want/searching , but for me it does not work at all ) .

Thank you

I asked a similar question - seems a good idea, haven’t got round to implementing it yet - not getting that many errors ( :wink: ), it was a bit of a [URL=“http://en.wikipedia.org/wiki/YAGNI”]yagni.

for example the ajax page should get latest 10 lines each 3 seconds using a #tail -10 logfile (the line could be passed with php shell_exec),
compare them with latest 10 received , and if they changed , refresh the web page each 6 seconds (i.e.) .

My problem is with ajax , I am fully inexpert. Anyone can help please ?
I am searching for an already coded script on google , but nothing…

Yeah, I like that idea.

anyone found a way ?

Not here I am afraid, still interested in it though.

for example the ajax page should get latest 10 lines each 3 seconds using a #tail -10 logfile (the line could be passed with php shell_exec),
compare them with latest 10 received , and if they changed , refresh the web page each 6 seconds (i.e.) .

Wouldn’t you check if the log file had updated in the last 3 seconds first, or do nothing?

Fancy spec’ing it out on here?

I’ve done it before, although I left a long running HTTP request open though, so I didn’t need to pass around the pointer’s current position. There’s no need to use the tail program (comparing lines is unneeded complexity).

http://php.net/ftell
http://php.net/fseek

Example:

The top is a real-time dump of a log file.

sk89q,

I don’t suppose you have source available for that top frame, by chance?

Thanks,

  • Nathan

I don’t know where the source for that is anymore, but it went something like this…

<?php
$fp = fopen("log.txt", "r");
fseek($fp, -500, SEEK_END); // 500 bytes back

// get the last 10 lines
$line_buffer = array();
while (!feof($fp)) {
    $line = fgets($fp, 1024);
    $line_buffer[] = $line;
    $line_buffer = array_slice($line_buffer, -10, 10);
}
// the above can be made to work quicker, but it'd use more memory

// print those lines
foreach ($line_buffer as $line) {
    echo $line;
}

// print new changes
while (true) {
    $line = fgets($fp, 1024); // blocking
    echo $line;
}