log4perl icon indicating copy to clipboard operation
log4perl copied to clipboard

Log::Log4perl::DateFormat caches time zone offset

Open provtemp opened this issue 4 years ago • 1 comments

Log::Log4perl::DateFormat computes the time zone offset only once, so Lo4perl ends up logging incorrect datetimes when the object survives during time zone changes.

% faketime '2021-03-28 01:59:58' perl -MLog::Log4perl -E 'sub g {Log::Log4perl::DateFormat->new("yyyy-MM-ddTHH:mm:ss.SSSZ")}; my $outer = g(); for (1..5) { say join " ", $outer->format(time), g->format(time); sleep 1 }'
2021-03-28T01:59:58.000+0100 2021-03-28T01:59:58.000+0100
2021-03-28T01:59:59.000+0100 2021-03-28T01:59:59.000+0100
2021-03-28T03:00:00.000+0100 2021-03-28T03:00:00.000+0200
2021-03-28T03:00:01.000+0100 2021-03-28T03:00:01.000+0200
2021-03-28T03:00:02.000+0100 2021-03-28T03:00:02.000+0200

provtemp avatar Apr 16 '21 10:04 provtemp

How expensive is it to look up the timezone offset? If it's cheap, it should be just not cached. If it's expensive, then this should be documented in e.g. an FAQ (so that a rolling restart of logging could be scheduled at TZ switch time). How do other logging daemons/libraries deal with this?

mohawk2 avatar Jun 01 '22 23:06 mohawk2