use of ch.qos.logback.core.rolling.RollingPolicyBase in project qpid-broker-j by apache.
the class AppenderUtils method configureRollingFileAppender.
public static void configureRollingFileAppender(FileLoggerSettings fileLoggerSettings, Context loggerContext, RollingFileAppender<ILoggingEvent> appender) {
String fileName = fileLoggerSettings.getFileName();
File file = new File(fileName);
if (file.getParentFile() != null) {
file.getParentFile().mkdirs();
}
validateLogFilePermissions(file);
validateMaxFileSize(fileLoggerSettings.getMaxFileSize());
appender.setFile(fileName);
appender.setAppend(true);
appender.setContext(loggerContext);
TriggeringPolicy triggeringPolicy;
RollingPolicyBase rollingPolicy;
final String maxFileSizeAsString = String.valueOf(fileLoggerSettings.getMaxFileSize()) + "MB";
if (fileLoggerSettings.isRollDaily()) {
DailyTriggeringPolicy dailyTriggeringPolicy = new DailyTriggeringPolicy(fileLoggerSettings.isRollOnRestart(), maxFileSizeAsString);
dailyTriggeringPolicy.setContext(loggerContext);
TimeBasedRollingPolicy<ILoggingEvent> timeBasedRollingPolicy = new TimeBasedRollingPolicy<>();
timeBasedRollingPolicy.setMaxHistory(fileLoggerSettings.getMaxHistory());
timeBasedRollingPolicy.setTimeBasedFileNamingAndTriggeringPolicy(dailyTriggeringPolicy);
timeBasedRollingPolicy.setFileNamePattern(fileName + ".%d{yyyy-MM-dd}.%i" + (fileLoggerSettings.isCompressOldFiles() ? ".gz" : ""));
rollingPolicy = timeBasedRollingPolicy;
triggeringPolicy = dailyTriggeringPolicy;
} else {
SizeTriggeringPolicy sizeTriggeringPolicy = new SizeTriggeringPolicy(fileLoggerSettings.isRollOnRestart(), maxFileSizeAsString);
sizeTriggeringPolicy.setContext(loggerContext);
SimpleRollingPolicy simpleRollingPolicy = new SimpleRollingPolicy(fileLoggerSettings.getMaxHistory());
simpleRollingPolicy.setFileNamePattern(fileName + ".%i" + (fileLoggerSettings.isCompressOldFiles() ? ".gz" : ""));
rollingPolicy = simpleRollingPolicy;
triggeringPolicy = sizeTriggeringPolicy;
}
rollingPolicy.setContext(loggerContext);
RollingPolicyDecorator decorator = new RollingPolicyDecorator(rollingPolicy, fileLoggerSettings.getRolloverListener(), fileLoggerSettings.getExecutorService());
decorator.setParent(appender);
appender.setRollingPolicy(decorator);
appender.setTriggeringPolicy(triggeringPolicy);
decorator.start();
triggeringPolicy.start();
final PatternLayoutEncoder encoder = new PatternLayoutEncoder();
encoder.setPattern(fileLoggerSettings.getLayout());
encoder.setContext(loggerContext);
encoder.start();
appender.setEncoder(encoder);
}
Aggregations