On Jul 20, 2007, at 7:33 AM, Hill, Alex wrote:
Hi,
I'm currently using log4j 1.2.14 and have been having some trouble
logging in GMT. Is there any way of setting the timezone of an
appender?
I ended up doing this:
TimeZone.setDefault(TimeZone.getTimeZone("GMT"));
This seems to work but it means my appender has to set this property
globally. This isn't ideal as it may cause unexpected results in any
applications using my appender.
I saw somewhere that ConversionPattern has been extended in version
1.3
to take a second parameter for a timezone such as below:
log4j.appender.FILE.layout.conversionPattern = %d{yyyy-MM-dd
hh:mm:ss z}{GMT+0} %-5p [%c{1}:%t] %m%n
The log4j 1.3 PatternLayout has been backported for use with log4j
1.2 as part of the "extras" companion which has not yet been
released. A release candidate is available at http://
people.apache.org/builds/logging/log4j/companions/extras/1.0/. Place
the apache-log4j-extras-1.0.jar in the classpath and change the class
name from o.a.l.PatternLayout to o.a.l.EnhancedPatternLayout and you
should have all of the log4j 1.3 pattern features. I would
appreciate any feedback on the release candidate reported to log4j-dev.
Will this mean that the time based rolling appenders will roll
correctly
at the end of day as specified by the time zone or is this purely for
the date text in the log? Is there a better way to specify the
timezone
properly?
The extras companions also include the log4j 1.3
org.apache.log4j.rolling RollingFileAppenders. I need to make sure
that they use the EnhancedPatternLayout, but they should be able to
roll at midnight local time. The stock DailyRollingFileAppender
however isn't affected by the presence of the enhanced pattern layout.
I extended the DailyRollingFileAppender to delete out of date
files, as
it rolls, in order to clean up. This seems to have been deprecated and
made final in version 1.3. Is it neccesary to make it final?
You may be looking at log4j 1.3 at the time DailyRollingFileAppender
was rewritten to delegate to
org.apache.log4j.rolling.RollingFileAppender (at least it was an
improvement over not having DRFA at all). The current SVN HEAD does
mark DRFA as deprecated and has some minor other changes, but it is
not marked final.
Deleting out of date files have always been problematic since you
could easily use a date pattern than omitted significant parts of the
date and you couldn't infer the actual time from the file name. I'd
suggest using the o.a.l.rolling.RFA with an custom TriggeringPolicy.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]