Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

Re: Lammentful logs fouled by failing filehandling

by eyepopslikeamosquito (Chancellor)
on May 01, 2012 at 10:09 UTC ( #968222=note: print w/replies, xml ) Need Help??

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:

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; } }
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.

Replies are listed 'Best First'.
Re^2: Lammentful logs fouled by failing filehandling
by shain (Initiate) on May 01, 2012 at 15:10 UTC

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://968222]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (8)
As of 2017-03-30 15:22 GMT
Find Nodes?
    Voting Booth?
    Should Pluto Get Its Planethood Back?

    Results (360 votes). Check out past polls.