TimeBasedRollingPolicy
is both easy to configure and quite powerful. In order to use TimeBasedRollingPolicy
, the FileNamePattern option must be set. It basically specifies the name of the rolled log files. The value FileNamePattern
should consist of the name of the file, plus a suitably placed %d
conversion specifier. The %d
conversion specifier may contain a date and time pattern as specified by the {@link java.text.SimpleDateFormat} class. If the date and time pattern is ommitted, then the default pattern of "yyyy-MM-dd" is assumed. The following examples should clarify the point.
FileNamePattern value | Rollover schedule | Example |
---|---|---|
/wombat/folder/foo.%d | Daily rollover (at midnight). Due to the omission of the optional time and date pattern for the %d token specifier, the default pattern of "yyyy-MM-dd" is assumed, which corresponds to daily rollover. | During November 23rd, 2004, logging output will go to the file /wombat/foo.2004-11-23 . At midnight and for the rest of the 24th, logging output will be directed to /wombat/foo.2004-11-24 . |
/wombat/foo.%d{yyyy-MM}.log | Rollover at the beginning of each month. | During the month of October 2004, logging output will go to /wombat/foo.2004-10.log . After midnight of October 31st and for the rest of November, logging output will be directed to /wombat/foo.2004-11.log . |
TimeBasedRollingPolicy
supports automatic file compression. This feature is enabled if the value of the FileNamePattern option ends with .gz
or .zip
.
FileNamePattern value | Rollover schedule | Example |
---|---|---|
/wombat/foo.%d.gz | Daily rollover (at midnight) with automatic GZIP compression of the arcived files. | During November 23rd, 2004, logging output will go to the file /wombat/foo.2004-11-23 . However, at midnight that file will be compressed to become /wombat/foo.2004-11-23.gz . For the 24th of November, logging output will be directed to /wombat/folder/foo.2004-11-24 until its rolled over at the beginning of the next day. |
The active file is defined as the log file for the current period whereas archived files are thos files which have been rolled over in previous periods.
By setting the ActiveFileName option you can decouple the location of the active log file and the location of the archived log files.
FileNamePattern value | ActiveFileName | Rollover schedule | Example |
---|---|---|---|
/wombat/foo.log.%d | /wombat/foo.log | Daily rollover. | During November 23rd, 2004, logging output will go to the file /wombat/foo.log . However, at midnight that file will archived as /wombat/foo.log.2004-11-23 . For the 24th of November, logging output will be directed to /wombat/folder/foo.log until its archived as /wombat/foo.log.2004-11-24 at the beginning of the next day. |
If configuring programatically, do not forget to call {@link #activateOptions}method before using this policy. Moreover, {@link #activateOptions} of TimeBasedRollingPolicy
must be called before calling the {@link #activateOptions} method of the owningRollingFileAppender
.
@author Ceki Gülcü
@since 1.3
|
|
|
|
|
|
|
|
|
|