in reply to Lammentful logs fouled by failing filehandling
Kudos on the amusing node title. And your coding style did not cause me to pull a face. That said, I made some minor "improvements" based on my personal taste:
Note the minor differences and make up your own mind. In particular, note the use of sprintf so that the dates and times are formatted more uniformly and thus sort correctly.sub logger { my $entry = shift; my $logpath = 'C:\\Logs\\MailServer\\'; my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localti +me; my $datestamp = sprintf '%04d_%02d_%02d', 1900+$year, 1+$mon, $mda +y; my $timestamp = sprintf '~<%02d:%02d:%02d>~', $hour, $min, $sec; my $logname = $logpath . $datestamp . '.log'; my $logline = $timestamp . $entry; if (defined $entry) { open my $LOG, '>>', $logname or die "open: '$logname': $!"; say $LOG $logline or die "say: '$logname': $!"; say $logline; close $LOG; } }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Lammentful logs fouled by failing filehandling
by shain (Initiate) on May 01, 2012 at 15:10 UTC |
In Section
Seekers of Perl Wisdom