logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Curt Arnold <carn...@apache.org>
Subject Re: Timestamps and time zones
Date Sun, 19 Oct 2008 21:47:24 GMT

On Oct 19, 2008, at 3:12 PM, Peter Steele wrote:

> We've noticed somewhat undersirable logging behavior when we change  
> the
> time zone our appllicaton is running under. When the application  
> starts,
> the timestamps used in our log files match the current local time,
> albeit without an explicit time zone identifier included in the time,
> but that's okay. However, if we change the time zone, e.g. from 8:00  
> am
> PDT to 8:00 am EDT, while the local time simply starts displaying the
> new time zone identifier, the log timestamps get shifted by the
> difference in the time zones. In this specific case, the log  
> timestamps
> would get shifted to 5:00 am.

> If we then stop and restart the application, the timestamps are then
> based again on the local time (8:00 am instead of 5:00 am). This is  
> what
> we want of course, but we want this to happen dynamically as well and
> not have to restart the application to get the timestamps in sync with
> the local time. How can we accomplish this? We want the timestamps to
> match whatever the local time is, regardless of the time zone, even
> after a time zone change. Is there a logger call we can make?

If you are changing from 8:00 AM PDT to 8:00 AM EDT, you are not just  
changing the time zone, but you are also changing the time.  If you  
are using a timestamp (milliseconds since the epoch), then they value  
would change when you changed the time though it should not be  
affected if you just changed the timezone.

Are you changing the timezone using a operating system utility  
(control panel etc) or by using a call to TimeZone.setDefault()?   
Different JVM's may have different approaches to how a change in the  
operating system timezone becomes visible in the JDK.  If the JDK only  
checks the default timezone at start up, there is nothing log4j can  
do.  Knowing the vendor and version of the OS and JVM in use and the  
exact method of making the timezone change would be helpful to  
understand your observed behavior.  It does appear that you are seeing  
an immediate effect from changing the time, but the timezone is not  
immediately updated in the app by the manner you are making the change.

I'd suggest using the EnhancedPatternLayout in the extras companion  
and output the time in a fixed timezone.  Something like:

%d{yyyy-MM-dd HH:mm:ss}{UTC}Z - %c - %m%n

You could also output the time in local time for convenience, but  
you'd always have the time in a known timezone.

To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org

View raw message