in reply to Re: Remembering Log Location after process dies.
in thread Remembering Log Location after process dies.

Howdy Mr Grabnar, I am using the following to try and read the file but I get no output. I installed the module and get no warnings about it, but I can't seem to get any output. And the log file does exist. Here's the code I am using:
#!/usr/bin/perl -w use File::Tail; my $LogFile="/usr/local/apache2/eventmgr/ncomount/page.log"; my $file=File::Tail->new("$LogFile"); while (defined($line=$file->read)) { print "$line"; }

Replies are listed 'Best First'.
Re: Re: Re: Remembering Log Location after process dies.
by matija (Priest) on Mar 04, 2004 at 22:09 UTC
    Your code looks OK. So let me list a few reasons why you might not get any output:
    • By deafult, File::Tail starts reading at the file's end. So if nothing has been written to the file from the time when you opened it to the time when you kill the script, you won't get any data.

      Solution: Write some data to the file, or start File::Tail with          $file=File::Tail->new(name=>$name, tail=>10);.

      That will tell File::Tail to first feed you the last ten lines in the file, and then wait for new data.

    • You just wrote some data, but File::Tail has not returned any yet.

      File::Tail strives to be as efficient as possible, and place as little unneeded load on the system as possible. To accomplish this, File::Tail remembers how long it has been since it last found new data in the file. And it sleeps that long before checking the file again.

      Solution:Wait a few minutes (if it has been long from the time when you opened the file to first new data), or start File::Tail by explicitly specifying the maximum idle time:

      $file=File::Tail->new(name=>$name, maxinterval=>10);
      With that, File::Tail will never wait more than 10 seconds before checking the file.
      Well that's slicker than buzzard poop on a pump handle. I finally waited long enough and it worked. I didn't realize that it did not read the file from the beginning and then start tracking the location. So it never starts until the first write to the log. That is exctly what I was after. TOO KEWL!!!! Thank you very much Mr Grabnar. You ROCK Dude!!!!!!!!!!! Thank you, thank you.... Danny