Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: Lammentful logs fouled by failing filehandling

by eyepopslikeamosquito (Canon)
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.


Comment on Re: Lammentful logs fouled by failing filehandling
Download Code
Re^2: Lammentful logs fouled by failing filehandling
by shain (Initiate) on May 01, 2012 at 15:10 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://968222]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (5)
As of 2014-10-26 09:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (152 votes), past polls