Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

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]
[Corion]: A good morning!
[Discipulus]: good morning Corion!
[Corion]: I spent parts of yesterday digging into Filter::Simple to make it not change the line numbers of unfiltered code, but I think I need regex help (which will come in a SoPW I guess). I tried @lines = /((?:"...."|[^" \n]+)\n)/gs, but that matched on...
[Corion]: ... foo "\0\0\0\n" bar\n by matching the first \n instead of matching the four-bytes-in- double-quotes part
[Corion]: ... and I still don't understand why ;)

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (11)
As of 2017-01-23 08:00 GMT
Find Nodes?
    Voting Booth?
    Do you watch meteor showers?

    Results (191 votes). Check out past polls.