]
RH Bugzilla Integration updated LOGMGR-119:
-------------------------------------------
Bugzilla Update: Perform
Bugzilla References:
Wrong backup file names by PeriodicRotatingFileHandler when suffix
"yyyy-ww"
----------------------------------------------------------------------------
Key: LOGMGR-119
URL:
https://issues.jboss.org/browse/LOGMGR-119
Project: JBoss Log Manager
Issue Type: Bug
Affects Versions: 1.5.2.Final
Reporter: Osamu Nagano
Assignee: James Perkins
When {{PeriodicRotatingFileHandler}} with suffix "yyyy-ww" rotates a log file
over a year, file that belongs to the new year is incorrectly named using the previous
year.
Here is a demonstrating test code supposed to be pasted into
{{src/test/java/org/jboss/logmanager/handlers/PeriodicSizeRotatingFileHandlerTests.java}}.
It mimics a record started from 2014-12-24 and the resulting backup log file is named
{{rotating-file-handler.log.2014-01}}. It should be 2015 instead.
{code}
/*
* Run with the following command:
* mvn compile test
-Dtest=PeriodicSizeRotatingFileHandlerTests#testPeriodicRotateWeekOfYear
*/
@Test
public void testPeriodicRotateWeekOfYear() throws Exception {
SimpleDateFormat fmt = periodFormatMap.get(Calendar.WEEK_OF_YEAR);
Calendar cal =
Calendar.getInstance(java.util.TimeZone.getTimeZone("GMT"));
PeriodicRotatingFileHandler handler = new PeriodicRotatingFileHandler();
handler.setAutoFlush(true);
handler.setFormatter(new PatternFormatter("%d{yyyy-MM-dd HH:mm:ss,SSS} %-5p
[%c] (%t) %s%E%n"));
handler.setSuffix("." + fmt.toPattern());
handler.setFile(logFile);
cal.set(Calendar.YEAR, 2014);
cal.set(Calendar.MONTH, 12 - 1);
cal.set(Calendar.DAY_OF_MONTH, 24);
cal.set(Calendar.HOUR_OF_DAY, 12);
for (int i = 0; i < 14; i++) {
long tim = cal.getTimeInMillis();
String fdate = fmt.format(tim);
ExtLogRecord record = createLogRecord("%02d th formatted date is %s",
i, fdate);
record.setMillis(tim);
handler.publish(record);
cal.add(Calendar.DAY_OF_MONTH, 1);
}
handler.close();
for (String logFile : BASE_LOG_DIR.list()) {
System.out.println(logFile);
}
Assert.assertTrue("Dummy.", true);
}
{code}
And here is the result of the test method.
{code}
% ll logs
total 12K
-rw-r--r--. 1 onagano onagano 228 Dec 5 17:09 rotating-file-handler.log
-rw-r--r--. 1 onagano onagano 532 Dec 5 17:09 rotating-file-handler.log.2014-01
-rw-r--r--. 1 onagano onagano 0 Dec 5 17:09 rotating-file-handler.log.2014-49
-rw-r--r--. 1 onagano onagano 304 Dec 5 17:09 rotating-file-handler.log.2014-52
% cat logs/rotating-file-handler.log.2014-52
2014-12-24 21:09:43,921 INFO [null] (main) 00 th formatted date is 2014-52
2014-12-25 21:09:43,921 INFO [null] (main) 01 th formatted date is 2014-52
2014-12-26 21:09:43,921 INFO [null] (main) 02 th formatted date is 2014-52
2014-12-27 21:09:43,921 INFO [null] (main) 03 th formatted date is 2014-52
% cat logs/rotating-file-handler.log.2014-01
2014-12-28 21:09:43,921 INFO [null] (main) 04 th formatted date is 2014-01
2014-12-29 21:09:43,921 INFO [null] (main) 05 th formatted date is 2014-01
2014-12-30 21:09:43,921 INFO [null] (main) 06 th formatted date is 2014-01
2014-12-31 21:09:43,921 INFO [null] (main) 07 th formatted date is 2014-01
2015-01-01 21:09:43,921 INFO [null] (main) 08 th formatted date is 2015-01
2015-01-02 21:09:43,921 INFO [null] (main) 09 th formatted date is 2015-01
2015-01-03 21:09:43,921 INFO [null] (main) 10 th formatted date is 2015-01
% cat logs/rotating-file-handler.log
2015-01-04 21:09:43,921 INFO [null] (main) 11 th formatted date is 2015-02
2015-01-05 21:09:43,921 INFO [null] (main) 12 th formatted date is 2015-02
2015-01-06 21:09:43,921 INFO [null] (main) 13 th formatted date is 2015-02
{code}