use of ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP in project dropwizard by dropwizard.
the class FileAppenderFactory method buildAppender.
protected FileAppender<E> buildAppender(LoggerContext context) {
if (archive) {
final RollingFileAppender<E> appender = new RollingFileAppender<>();
appender.setFile(currentLogFilename);
appender.setBufferSize(new FileSize(bufferSize.toBytes()));
if (maxFileSize != null && !archivedLogFilenamePattern.contains("%d")) {
final FixedWindowRollingPolicy rollingPolicy = new FixedWindowRollingPolicy();
rollingPolicy.setContext(context);
rollingPolicy.setMaxIndex(getArchivedFileCount());
rollingPolicy.setFileNamePattern(getArchivedLogFilenamePattern());
rollingPolicy.setParent(appender);
rollingPolicy.start();
appender.setRollingPolicy(rollingPolicy);
final SizeBasedTriggeringPolicy<E> triggeringPolicy = new SizeBasedTriggeringPolicy<>();
triggeringPolicy.setMaxFileSize(new FileSize(maxFileSize.toBytes()));
triggeringPolicy.setContext(context);
triggeringPolicy.start();
appender.setTriggeringPolicy(triggeringPolicy);
return appender;
} else {
final TimeBasedFileNamingAndTriggeringPolicy<E> triggeringPolicy;
if (maxFileSize == null) {
triggeringPolicy = new DefaultTimeBasedFileNamingAndTriggeringPolicy<>();
} else {
final SizeAndTimeBasedFNATP<E> maxFileSizeTriggeringPolicy = new SizeAndTimeBasedFNATP<>();
maxFileSizeTriggeringPolicy.setMaxFileSize(new FileSize(maxFileSize.toBytes()));
triggeringPolicy = maxFileSizeTriggeringPolicy;
}
triggeringPolicy.setContext(context);
final TimeBasedRollingPolicy<E> rollingPolicy = new TimeBasedRollingPolicy<>();
rollingPolicy.setContext(context);
rollingPolicy.setFileNamePattern(archivedLogFilenamePattern);
rollingPolicy.setTimeBasedFileNamingAndTriggeringPolicy(triggeringPolicy);
triggeringPolicy.setTimeBasedRollingPolicy(rollingPolicy);
rollingPolicy.setMaxHistory(archivedFileCount);
appender.setRollingPolicy(rollingPolicy);
appender.setTriggeringPolicy(triggeringPolicy);
rollingPolicy.setParent(appender);
rollingPolicy.start();
return appender;
}
}
final FileAppender<E> appender = new FileAppender<>();
appender.setFile(currentLogFilename);
appender.setBufferSize(new FileSize(bufferSize.toBytes()));
return appender;
}
use of ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP in project jmxtrans by jmxtrans.
the class TimeBasedRollingKeyOutWriter method initRollingPolicy.
protected RollingPolicy initRollingPolicy(String fileName, int maxBackupFiles, String maxFileSize) {
SizeAndTimeBasedFNATP sizeTimeBasedPolicy = new SizeAndTimeBasedFNATP();
// the max file size before rolling to a new file
sizeTimeBasedPolicy.setMaxFileSize(maxFileSize);
sizeTimeBasedPolicy.setContext(loggerContext);
TimeBasedRollingPolicy policy = new TimeBasedRollingPolicy();
// set the filename pattern
policy.setFileNamePattern(fileName);
// the maximum number of backup files to keep around
policy.setMaxHistory(maxBackupFiles);
policy.setTimeBasedFileNamingAndTriggeringPolicy(sizeTimeBasedPolicy);
policy.setContext(loggerContext);
return policy;
}
Aggregations