001/* 002 * Logback: the reliable, generic, fast and flexible logging framework. 003 * Copyright (C) 1999-2026, QOS.ch. All rights reserved. 004 * 005 * This program and the accompanying materials are dual-licensed under 006 * either the terms of the Eclipse Public License v2.0 as published by 007 * the Eclipse Foundation 008 * 009 * or (per the licensee's choosing) 010 * 011 * under the terms of the GNU Lesser General Public License version 2.1 012 * as published by the Free Software Foundation. 013 */ 014package ch.qos.logback.core.rolling; 015 016import ch.qos.logback.core.rolling.SizeAndTimeBasedFileNamingAndTriggeringPolicy.Usage; 017import ch.qos.logback.core.util.FileSize; 018 019public class SizeAndTimeBasedRollingPolicy<E> extends TimeBasedRollingPolicy<E> { 020 021 static long MAX_COMPRESSION_FACTOR = 20; 022 023 FileSize maxFileSize; 024 025 @Override 026 public void start() { 027 SizeAndTimeBasedFileNamingAndTriggeringPolicy<E> sizeAndTimeBasedFNATP = new SizeAndTimeBasedFileNamingAndTriggeringPolicy<E>(Usage.EMBEDDED); 028 if (maxFileSize == null) { 029 addError("maxFileSize property is mandatory."); 030 return; 031 } else { 032 addInfo("Archive files will be limited to [" + maxFileSize + "] each."); 033 } 034 035 sizeAndTimeBasedFNATP.setMaxFileSize(maxFileSize); 036 timeBasedFileNamingAndTriggeringPolicy = sizeAndTimeBasedFNATP; 037 038 if (!isUnboundedTotalSizeCap() && totalSizeCap.getSize() < maxFileSize.getSize()/MAX_COMPRESSION_FACTOR) { 039 addWarn("totalSizeCap of [" + totalSizeCap + "] is much smaller than maxFileSize [" + maxFileSize 040 + "] which is non-sensical, even taking compression into account."); 041 } 042 043 // most work is done by the parent 044 super.start(); 045 } 046 047 public void setMaxFileSize(FileSize aMaxFileSize) { 048 this.maxFileSize = aMaxFileSize; 049 } 050 051 @Override 052 public String toString() { 053 return "c.q.l.core.rolling.SizeAndTimeBasedRollingPolicy@" + this.hashCode(); 054 } 055}