0

My web server is in a timezone different from mine and I am using this pattern layout in the Log4perl config:

log4perl.appender.LOGFILE.layout=PatternLayout
log4perl.appender.LOGFILE.layout.ConversionPattern=%d | %p | %l | %c | %m%n

The %d produces a date/time in the timezone of the server. How can I make it log the date/time in my local timezone instead?

I am aware that the following:

$Log::Log4perl::DateFormat::GMTIME = 1;

Causes date/time to be logged in GMT however I could find nothing in the documentation to support arbitrary timezones.

noswonky
  • 3
  • 1
  • 3
    Not an answer, but I highly recommend just logging everything in UTC (what used to be called GMT), whether the server is in your local time zone or not. It avoids a lot of confusion in log processing and analysis. – Mark Reed Jun 17 '12 at 12:20

1 Answers1

1

If you set the time zone for Perl in general, that will fix the logs, too. Might be too blunt an instrument for your purposes:

use POSIX qw(tzset);

$ENV{TZ} = 'desired time zone goes here';
tzset;

To go even blunter, if you have access, you can set TZ in the environment of the web server itself and have everything in the desired zone.

But I think you're better off logging everything in UTC.

Mark Reed
  • 91,912
  • 16
  • 138
  • 175