logging-log4cxx-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Peter Steiner <peter.stei...@hugwi.ch>
Subject configuring RollingFileAppenders with properties
Date Thu, 14 Dec 2006 08:27:32 GMT
Hello all

Quite frequently I see the question popping, how you can have one log
file per day, even when you use an INI file (a.k.a. properties) for the
configuration.

There are two roads:
- use the DailyRollingFileAppender. This is documented as deprecated,
  but with the recent commits from Curt (486425 and earlier) this
  probably works out of the box (I have not tested this).
- use the new style RollingFileAppender with a TimeBasedRollingPolicy.
  To configure the policy from properties, you need the patch
  (originally by Christian Steindl) from
  http://issues.apache.org/jira/browse/LOGCXX-102

Here is an example configuration for TimeBasedRollingPolicy and one log
file per day:

log4j.appender.D=org.apache.log4j.rolling.RollingFileAppender
log4j.appender.D.rollingPolicy=TimeBasedRollingPolicy
log4j.appender.D.rollingPolicy.FileNamePattern=%d.log

Another example: if you want a new log file every hour, you can replace
the FileNamePattern line with this one:

log4j.appender.D.rollingPolicy.FileNamePattern=%d{yyyy-MM-dd-HH}.log

There is another caveat (unrelated to properties) when using a
configuration which needs to rename files (say when you use
FixedWindowRollingPolicy with a MaxIndex). Whenever a rename happens,
log4cxx will allocate a small amount of memory that won't be freed until
the end of the application. To fix this, you need the 'mutex' patch from
http://issues.apache.org/jira/browse/LOGCXX-161.

HTH

Peter
-- 
    _   _        Peter Steiner <peter.steiner@hugwi.ch>
  / /_/ /        Hug-Witschi AG <http://www.hugwi.ch/>
 /  _  /         Electronic Engineering
/_/ /_/  _   _   Auriedstrasse 10
   / / / / / /   CH-3178 Boesingen
  / /_/ /_/ /    Tel  +41 31 740 44 44
 /_ _ _ _ _/     Fax  +41 31 740 44 45

Mime
View raw message