View Javadoc
1   /**
2    * Logback: the reliable, generic, fast and flexible logging framework.
3    * Copyright (C) 1999-2015, QOS.ch. All rights reserved.
4    *
5    * This program and the accompanying materials are dual-licensed under
6    * either the terms of the Eclipse Public License v1.0 as published by
7    * the Eclipse Foundation
8    *
9    *   or (per the licensee's choosing)
10   *
11   * under the terms of the GNU Lesser General Public License version 2.1
12   * as published by the Free Software Foundation.
13   */
14  package ch.qos.logback.core.rolling;
15  
16  import ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP.Usage;
17  import ch.qos.logback.core.util.FileSize;
18  
19  public class SizeAndTimeBasedRollingPolicy<E> extends TimeBasedRollingPolicy<E> {
20  
21      FileSize maxFileSize;
22  
23      @Override
24      public void start() {
25          SizeAndTimeBasedFNATP<E> sizeAndTimeBasedFNATP = new SizeAndTimeBasedFNATP<E>(Usage.EMBEDDED);
26          if (maxFileSize == null) {
27              addError("maxFileSize property is mandatory.");
28              return;
29          } else {
30              addInfo("Archive files will be limited to [" + maxFileSize + "] each.");
31          }
32  
33          sizeAndTimeBasedFNATP.setMaxFileSize(maxFileSize);
34          timeBasedFileNamingAndTriggeringPolicy = sizeAndTimeBasedFNATP;
35  
36          if (!isUnboundedTotalSizeCap() && totalSizeCap.getSize() < maxFileSize.getSize()) {
37              addError("totalSizeCap of [" + totalSizeCap + "] is smaller than maxFileSize [" + maxFileSize
38                      + "] which is non-sensical");
39              return;
40          }
41  
42          // most work is done by the parent
43          super.start();
44      }
45  
46      public void setMaxFileSize(FileSize aMaxFileSize) {
47          this.maxFileSize = aMaxFileSize;
48      }
49  
50      @Override
51      public String toString() {
52          return "c.q.l.core.rolling.SizeAndTimeBasedRollingPolicy@" + this.hashCode();
53      }
54  }