Re: logrotate and perl file handles. How do I know when to reopen my log file?

From: Teamsolco (teamsolco_at_teamdelsol.com)
Date: 01/30/04


To: "Robby Russell" <rrussell@commandprompt.com>
Date: Thu, 29 Jan 2004 17:02:11 -0700

I think you have me backwards. I'm not monitoring the log file, I'm writing to it (append mode). Within perl, I need
to know when an outside process has renamed the log file so I can reinitialize the log output to a new file (the correct
file name).

----- Original Message -----
From: "Robby Russell" <rrussell@commandprompt.com>
To: "TeamSolCO" <teamsolco@teamdelsol.com>
Sent: Thursday, January 29, 2004 4:54 PM
Subject: Re: logrotate and perl file handles. How do I know when to reopen my log file?

: TeamSolCO typed this on 01/29/2004 01:16 PM:
: > I have written a long running perl application to help me with some trivial administrative functions. Due to
the
: > volume of logging generated by this application, I am managing its output with logrotate. The problem I face is
that
: > perl is "following" the log files that logrotate swaps out. While this is probably intelligent on perl's part (to
: > follow the file descriptor rather than the file name), it is presenting a major problem for me. When "logfile"
becomes
: > "logfile.1" (etc), my application follows that move and "continues" logging to the new "logfile.1" instead of losing
: > that file handle -- a condition which I check for so that I can reopen the log file using the proper file name,
: > "logfile".
: > Ultimately, perl will only lose the file handle when logrotate finally deletes the "last file" in the log
rotation
: > scheme. Unfortunately, I will have lost a week's worth of logs because all that data will have been in the single
file.
: > Additionally, I'll have several empty log file copies named .1, .2, .3, etc. How can I set perl to NOT follow the
file
: > when it is renamed by logrotate, such that a condition will be created where I will be able to initialize the
: > replacement file?
: >
: > Thanks!!
: >
: > - William Kimball
: > "Programming is an art-form that fights back!"
: >
:
: Do you want to only monitor the original logfile or logfile.1 as well?
:
: You can use the perl module, File::Tail for monitoring logfile, even
: through logrotate.
:
: -Robby
:
:
: --
: #-------------------------------------------------------
: # Robby Russell, | Sr. Administrator / Lead Programmer
: # Command Prompt, Inc. | http://www.commandprompt.com
: # rrussell@commandprompt.com | Telephone: (503) 667.4564
: #-------------------------------------------------------
:
:



Relevant Pages

  • How do I check to see if an open filehandle is still open?
    ... I have a long running perl application that appends to a log file during operation. ... Unfortunately, I have learned the hard way that, when logrotate swaps the files ... how do I detect when an open filehandle has been lost? ...
    (perl.beginners)
  • Please critique this short script that scans a log file
    ... I'm new to Perl and wrote a simple script to scan a database log file ... with embedded timestamps. ...
    (comp.lang.perl.misc)
  • Re: Perl reliability?
    ... one log file, and sometimes it won't. ... Is Perl more stable on other platforms? ... If you could try it some how w/out threading, ... possibly not thread safe, possibly thread ...
    (comp.lang.perl.misc)
  • Re: WinNT ActiveState STDERR and STDOUT
    ... the background and capture the output of STDOUT ... and STDERR for later analysis. ... print("Hello World STDOUT from Perl"); ... I tried fudging it to a different log file (before I read this ...
    (comp.lang.perl.misc)
  • logrotate and perl file handles. How do I know when to reopen my log file?
    ... I have written a long running perl application to help me with some trivial administrative functions. ... volume of logging generated by this application, I am managing its output with logrotate. ... When "logfile" becomes ... Additionally, I'll have several empty log file copies named .1, .2, .3, etc. ...
    (perl.beginners)