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 java.io.File;
17  import java.util.Date;
18  
19  import ch.qos.logback.core.joran.spi.NoAutoStart;
20  import ch.qos.logback.core.rolling.helper.TimeBasedArchiveRemover;
21  
22  /**
23   * 
24   * @author Ceki Gülcü
25   * 
26   * @param <E>
27   */
28  @NoAutoStart
29  public class DefaultTimeBasedFileNamingAndTriggeringPolicy<E> extends TimeBasedFileNamingAndTriggeringPolicyBase<E> {
30  
31      @Override
32      public void start() {
33          super.start();
34          if (!super.isErrorFree())
35              return;
36          if(tbrp.fileNamePattern.hasIntegerTokenCOnverter()) {
37              addError("Filename pattern ["+tbrp.fileNamePattern+"] contains an integer token converter, i.e. %i, INCOMPATIBLE with this configuration. Remove it.");
38              return;
39          }
40          
41          archiveRemover = new TimeBasedArchiveRemover(tbrp.fileNamePattern, rc);
42          archiveRemover.setContext(context);
43          started = true;
44      }
45  
46      public boolean isTriggeringEvent(File activeFile, final E event) {
47          long time = getCurrentTime();
48          if (time >= nextCheck) {
49              Date dateOfElapsedPeriod = dateInCurrentPeriod;
50              addInfo("Elapsed period: " + dateOfElapsedPeriod);
51              elapsedPeriodsFileName = tbrp.fileNamePatternWithoutCompSuffix.convert(dateOfElapsedPeriod);
52              setDateInCurrentPeriod(time);
53              computeNextCheck();
54              return true;
55          } else {
56              return false;
57          }
58      }
59  
60      @Override
61      public String toString() {
62          return "c.q.l.core.rolling.DefaultTimeBasedFileNamingAndTriggeringPolicy";
63      }
64  }