On Fri, 22 Jan 2010, Rob Retter wrote:

I sent this message a little while ago

Sorry for the delay, thanks for your patience.

In DateFormat.pm, the routine fmt() should not bother to recreate the

This is a neat idea, we just need to change that the mere presence of
the Time::HiRes module introduces milliseconds and hence kills the
optimization.

More to come soon ...

-- Mike

Mike Schilli
m...@perlmeister.com

time string over and over and over....You tend to see the same
timestamp on numerous consecutive log entries (unless you're using
milliseconds, which seems like overkill in many situations).  Anyway,
the code should be something like:

{
my $lastSecs = 0;
my $lastMsecs = 0;
my $lastFmt = '';

###########################################
sub format {
###########################################
    my($self, $secs, $msecs) = @_;

    $msecs = 0 unless defined $msecs;

    return $lastFmt if ($lastSecs == $secs and
                        $lastMsecs == $msecs);

    my @time;

    if($GMTIME) {
        @time = gmtime($secs);
    } else {
        @time = localtime($secs);
    }

        # add milliseconds
    push @time, $msecs;

    my @values = ();

    for(@{$self->{stack}}) {
        my($val, $code) = @$_;
        if($code) {
            push @values, $code->($time[$val]);
        } else {
            push @values, $time[$val];
        }
    }

    $lastSecs = $secs;
    $lastMsecs = $msecs;
    $lastFmt = sprintf($self->{fmt}, @values);
    return $lastFmt;
}

}

------------------------------------------------------------------------------
The Planet: dedicated and managed hosting, cloud storage, colocation
Stay online with enterprise data centers and the best network in the business
Choose flexible plans and management services without long-term contracts
Personal 24x7 support from experience hosting pros just a phone call away.
http://p.sf.net/sfu/theplanet-com
_______________________________________________
log4perl-devel mailing list
log4perl-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/log4perl-devel
------------------------------------------------------------------------------
The Planet: dedicated and managed hosting, cloud storage, colocation
Stay online with enterprise data centers and the best network in the business
Choose flexible plans and management services without long-term contracts
Personal 24x7 support from experience hosting pros just a phone call away.
http://p.sf.net/sfu/theplanet-com
_______________________________________________
log4perl-devel mailing list
log4perl-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/log4perl-devel

Reply via email to