Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
I have written a script to look for a specific string occurring within a log on a windows system. The log fills up very quickly and therefore rolls over (rotates) often. For some reason though, while my script is running, the file will not roll-over, presumably because the rolling mechanism cannot get a suitable lock on the file. I have tried using File::Tail and POE::Wheel::FollowTail and both work fine except for not allowing the file to roll-over.

As an experiment, I have tried using SFU's "tail -f" and that doesn't keep the rollover from occurring, but of course also doesn't follow the new file when a roll-over does occur.

I can think of several ways to periodically release and re-open the file, but it is too easy to miss an occurrance of the issue that way.

I will paste the applicable code from both methods I have tried below.

Any enlightenment would be greatly appreciated,
-Frd

File::Tail code:

my $file=File::Tail->new(name=>"$SEARCH_LOG", maxinterval=>10); LogIt("Initiated 'tail' ... reading file '$SEARCH_LOG':\n"); LogIt(" ... Looking for '$STRING'\n"); while (defined(my $line=$file->read)) { LogIt("Read line: $line"); next unless ( $line =~ /$STRING/ ); LogIt("That Line MATCHES SEARCH STRING: '$STRING'\n"); lock($occurred); $occurred ++; LogIt("$line"); LogIt("Increasing OCCURRED flag to '$occurred'"); }

POE code:

POE::Session->create( inline_states => { _start => sub { $_[HEAP]{tailor} = POE::Wheel::FollowTail->new( Filename => "$SEARCH_LOG", InputEvent => "got_log_line", ResetEvent => "got_log_rollover", ); }, got_log_line => sub { my $line = $_[ARG0]; LogIt("Read line: $line"); return unless ( $line =~ /$STRING/ ); LogIt("That Line MATCHES SEARCH STRING: '$STRING'\n"); lock($occurred); $occurred++; LogIt("$line"); LogIt("Increasing OCCURRED flag to '$occurred'"); }, got_log_rollover => sub { LogIt("Log rolled over.\n"); }, } );

In reply to Tail'ing a log that frequently rolls over by frd1963

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (2)
As of 2024-03-19 06:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found