Are you sure that the log rotation isn't being done with a cp isn't of a mv for the log file that is currently being written too? Your code is written with the expectation that the log rotation software is performing the equivalent of an mv command, i.e. copy the file to a new name and the delete the old file.
It possible (and better) that the log rotation software is taking the following steps to rotate the logs;
- $ mv logfile.2 logfile.3
- $ mv logfile.1 logfile.2
- $ cp logfile logfile.1
- $ >logfile
For this example, only three old log files are being kept.
The last step will truncate the logfile to 0 bytes but doesn't cause a new file to be created so the inode number will not change. This is a better method because the process that is writing to the log file doesn't need to be restarted (or HUP'd).
Depending upon the frequency of the monitoring of the log file, just keeping track of the size of the file will allow you to know that the file has been truncated. If the file size is smaller than it was last time, you can be confident that the file has been truncated and you need to display all of it. Of course there is the risk that if the file is being written to quickly, this method won't pick up all of the changes.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.