SizeAndTimeBasedRollingPolicy.java
/*
* Logback: the reliable, generic, fast and flexible logging framework.
* Copyright (C) 1999-2026, QOS.ch. All rights reserved.
*
* This program and the accompanying materials are dual-licensed under
* either the terms of the Eclipse Public License v2.0 as published by
* the Eclipse Foundation
*
* or (per the licensee's choosing)
*
* under the terms of the GNU Lesser General Public License version 2.1
* as published by the Free Software Foundation.
*/
package ch.qos.logback.core.rolling;
import ch.qos.logback.core.rolling.SizeAndTimeBasedFileNamingAndTriggeringPolicy.Usage;
import ch.qos.logback.core.util.FileSize;
public class SizeAndTimeBasedRollingPolicy<E> extends TimeBasedRollingPolicy<E> {
static long MAX_COMPRESSION_FACTOR = 20;
FileSize maxFileSize;
@Override
public void start() {
SizeAndTimeBasedFileNamingAndTriggeringPolicy<E> sizeAndTimeBasedFNATP = new SizeAndTimeBasedFileNamingAndTriggeringPolicy<E>(Usage.EMBEDDED);
if (maxFileSize == null) {
addError("maxFileSize property is mandatory.");
return;
} else {
addInfo("Archive files will be limited to [" + maxFileSize + "] each.");
}
sizeAndTimeBasedFNATP.setMaxFileSize(maxFileSize);
timeBasedFileNamingAndTriggeringPolicy = sizeAndTimeBasedFNATP;
if (!isUnboundedTotalSizeCap() && totalSizeCap.getSize() < maxFileSize.getSize()/MAX_COMPRESSION_FACTOR) {
addWarn("totalSizeCap of [" + totalSizeCap + "] is much smaller than maxFileSize [" + maxFileSize
+ "] which is non-sensical, even taking compression into account.");
}
// most work is done by the parent
super.start();
}
public void setMaxFileSize(FileSize aMaxFileSize) {
this.maxFileSize = aMaxFileSize;
}
@Override
public String toString() {
return "c.q.l.core.rolling.SizeAndTimeBasedRollingPolicy@" + this.hashCode();
}
}