Search in sources :

Example 1 with SizeAndTimeBasedFNATP

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;
}
Also used : FileAppender(ch.qos.logback.core.FileAppender) RollingFileAppender(ch.qos.logback.core.rolling.RollingFileAppender) FixedWindowRollingPolicy(ch.qos.logback.core.rolling.FixedWindowRollingPolicy) RollingFileAppender(ch.qos.logback.core.rolling.RollingFileAppender) SizeBasedTriggeringPolicy(ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy) SizeAndTimeBasedFNATP(ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP) TimeBasedRollingPolicy(ch.qos.logback.core.rolling.TimeBasedRollingPolicy) FileSize(ch.qos.logback.core.util.FileSize)

Example 2 with SizeAndTimeBasedFNATP

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;
}
Also used : SizeAndTimeBasedFNATP(ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP) TimeBasedRollingPolicy(ch.qos.logback.core.rolling.TimeBasedRollingPolicy)

Aggregations

SizeAndTimeBasedFNATP (ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP)2 TimeBasedRollingPolicy (ch.qos.logback.core.rolling.TimeBasedRollingPolicy)2 FileAppender (ch.qos.logback.core.FileAppender)1 FixedWindowRollingPolicy (ch.qos.logback.core.rolling.FixedWindowRollingPolicy)1 RollingFileAppender (ch.qos.logback.core.rolling.RollingFileAppender)1 SizeBasedTriggeringPolicy (ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy)1 FileSize (ch.qos.logback.core.util.FileSize)1