in reply to Log rotating filter.
Still, from that experience, I can tell you that your pseudocode should work just fine. You don't necessarily have to rename the old log, though -- you could just reopen LOG with a new filename. Number them sequentially, or use some part of the time and date, or whatever. So something like (untested) this ought to work, as long as you don't need to restart your app using the same set of logs:
Although if you wanted to be able to seek directly to some offset within the overall log file, you might be better off using a global $size counter and naming the log files by the offset of their starting byte, or perhaps an initial line number (you'd just need to keep a $next_start = $size + $MAXSIZE around).my $log_number = 0; my $size = $MAXSIZE+1; while (<>) { if ($size > $MAXSIZE) { # This will automatically close the old log file open(LOG, ">log-" . ++$log_number) or die "open: $!"; $size = 0; } print LOG $_; $size += length($_); }
|
|---|