Timezone information in Log4j logs

View: New views
2 Messages — Rating Filter:   Alert me  

Timezone information in Log4j logs

by Das, Amar :: Rate this Message:

| View Threaded | Show Only this Message

Hi:

I have a program running on a server in Dallas. I need to generate log4j
output in timezone "America/New_York". How can I do that?


Current configuration is

log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d %p [%c] - %m%n

Thanks

Re: Timezone information in Log4j logs

by Curt Arnold-3 :: Rate this Message:

| View Threaded | Show Only this Message


On May 6, 2008, at 12:44 PM, Das, Amar wrote:

> Hi:
>
> I have a program running on a server in Dallas. I need to generate  
> log4j
> output in timezone "America/New_York". How can I do that?
>
>
> Current configuration is
>
> log4j.appender.stdout=org.apache.log4j.ConsoleAppender
> log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
> log4j.appender.stdout.layout.ConversionPattern=%d %p [%c] - %m%n
>
> Thanks

log4j usage questions should be asked on log4j-user@....

The enhanced pattern layout in the extras companions supports time  
zone specifiers on date formats.  To use:

Download the extras companion from http://logging.apache.org/log4j/companions/extras 
  and place jar on classpath.

> log4j.appender.stdout.layout=org.apache.log4j.EnhancedPatternLayout
> log4j.appender.stdout.layout.ConversionPattern=%d{}{America/
> New_York} %p [%c] - %m%n


The contents of the second brace pair is passed to  
java.util.TimeZone.getTimeZone() to get the appropriate time zone.  
There is a guaranteed set of time zone identifiers and then a lot that  
are platform or implementation specific.  If you use "America/
New_York", your configuration file may not work properly if you change  
platforms or implementations.  See the documentation of  
java.util.TimeZone.getTimeZone() for more specifics.