Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

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?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (6)
As of 2016-12-05 09:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    On a regular basis, I'm most likely to spy upon:













    Results (75 votes). Check out past polls.