RollingFileAppender appender = new RollingFileAppender();
appender.setContext(context);
appender.setName(appenderName);
- appender.setFile(new File(logsDir, filenamePrefix + ".log").getAbsolutePath());
+ String filePath = new File(logsDir, filenamePrefix + ".log").getAbsolutePath();
+ appender.setFile(filePath);
TimeBasedRollingPolicy rollingPolicy = new TimeBasedRollingPolicy();
rollingPolicy.setContext(context);
- rollingPolicy.setFileNamePattern(filenamePrefix + ".%d{" + datePattern + "}.log");
+ rollingPolicy.setFileNamePattern(StringUtils.replace(filePath, filenamePrefix + ".log", filenamePrefix + ".%d{" + datePattern + "}.log"));
rollingPolicy.setMaxHistory(maxFiles);
rollingPolicy.setParent(appender);
rollingPolicy.start();
RollingFileAppender appender = new RollingFileAppender();
appender.setContext(context);
appender.setName(appenderName);
- appender.setFile(new File(logsDir, filenamePrefix + ".log").getAbsolutePath());
+ String filePath = new File(logsDir, filenamePrefix + ".log").getAbsolutePath();
+ appender.setFile(filePath);
SizeBasedTriggeringPolicy trigger = new SizeBasedTriggeringPolicy(size);
trigger.setContext(context);
FixedWindowRollingPolicy rollingPolicy = new FixedWindowRollingPolicy();
rollingPolicy.setContext(context);
- rollingPolicy.setFileNamePattern(filenamePrefix + ".%i.log");
+ rollingPolicy.setFileNamePattern(StringUtils.replace(filePath, filenamePrefix + ".log", filenamePrefix + ".%i.log"));
rollingPolicy.setMaxIndex(1);
rollingPolicy.setMaxIndex(maxFiles);
rollingPolicy.setMaxIndex(maxFiles);
RollingFileAppender fileAppender = (RollingFileAppender) appender;
TimeBasedRollingPolicy triggeringPolicy = (TimeBasedRollingPolicy) fileAppender.getTriggeringPolicy();
assertThat(triggeringPolicy.getMaxHistory()).isEqualTo(7);
- assertThat(triggeringPolicy.getFileNamePattern()).isEqualTo("sonar.%d{yyyy-MM-dd}.log");
+ assertThat(triggeringPolicy.getFileNamePattern()).endsWith("sonar.%d{yyyy-MM-dd}.log");
}
@Test
RollingFileAppender fileAppender = (RollingFileAppender) appender;
FixedWindowRollingPolicy rollingPolicy = (FixedWindowRollingPolicy) fileAppender.getRollingPolicy();
assertThat(rollingPolicy.getMaxIndex()).isEqualTo(20);
- assertThat(rollingPolicy.getFileNamePattern()).isEqualTo("sonar.%i.log");
+ assertThat(rollingPolicy.getFileNamePattern()).endsWith("sonar.%i.log");
SizeBasedTriggeringPolicy triggeringPolicy = (SizeBasedTriggeringPolicy) fileAppender.getTriggeringPolicy();
assertThat(triggeringPolicy.getMaxFileSize()).isEqualTo("1MB");
}
// max 5 monthly files
TimeBasedRollingPolicy triggeringPolicy = (TimeBasedRollingPolicy) appender.getTriggeringPolicy();
assertThat(triggeringPolicy.getMaxHistory()).isEqualTo(20);
- assertThat(triggeringPolicy.getFileNamePattern()).isEqualTo("sonar.%d{yyyy-MM}.log");
+ assertThat(triggeringPolicy.getFileNamePattern()).endsWith("sonar.%d{yyyy-MM}.log");
}
@Test