SitePoint Sponsor

User Tag List

Results 1 to 13 of 13
  1. #1
    SitePoint Addict
    Join Date
    Feb 2004
    Location
    Rome
    Posts
    296
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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
    Last edited by graziano68; Sep 23, 2008 at 00:31.
    trcris ::> http://www.trcris.com

  2. #2
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Wow, that has to be the least documented project I've ever seen.

    Not one place does it actually say what it does.
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona

  3. #3
    SitePoint Evangelist -T-'s Avatar
    Join Date
    Jun 2002
    Posts
    444
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by arkinstall View Post
    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

    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
    chrome is a wrapper that combines a browser with spyware

  4. #4
    SitePoint Wizard
    Join Date
    Mar 2008
    Posts
    1,149
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.

  5. #5
    SitePoint Addict
    Join Date
    Feb 2004
    Location
    Rome
    Posts
    296
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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-...tailer-viewer/ , which is exactly what I want/searching , but for me it does not work at all ) .


    Thank you
    trcris ::> http://www.trcris.com

  6. #6
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    I asked a similar question - seems a good idea, haven't got round to implementing it yet - not getting that many errors ( ), it was a bit of a yagni.

  7. #7
    SitePoint Addict
    Join Date
    Feb 2004
    Location
    Rome
    Posts
    296
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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..
    trcris ::> http://www.trcris.com

  8. #8
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    Yeah, I like that idea.

  9. #9
    SitePoint Addict
    Join Date
    Feb 2004
    Location
    Rome
    Posts
    296
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    anyone found a way ?
    trcris ::> http://www.trcris.com

  10. #10
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    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?

  11. #11
    SitePoint Wizard
    Join Date
    Mar 2008
    Posts
    1,149
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by sk89q View Post
    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.
    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.

  12. #12
    SitePoint Member
    Join Date
    Nov 2008
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    sk89q,

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

    Thanks,

    - Nathan

  13. #13
    SitePoint Wizard
    Join Date
    Mar 2008
    Posts
    1,149
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I don't know where the source for that is anymore, but it went something like this...

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

    // get the last 10 lines
    $line_buffer = array();
    while (!
    feof($fp)) {
        
    $line fgets($fp1024);
        
    $line_buffer[] = $line;
        
    $line_buffer array_slice($line_buffer, -1010);
    }
    // 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($fp1024); // blocking
        
    echo $line;
    }


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •