View Javadoc

1   /**
2    * Logback: the reliable, generic, fast and flexible logging framework.
3    * Copyright (C) 1999-2011, 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.rolling.helper.TimeBasedArchiveRemover;
20  
21  /**
22   * 
23   * @author Ceki Gülcü
24   * 
25   * @param <E>
26   */
27  public class DefaultTimeBasedFileNamingAndTriggeringPolicy<E> extends
28      TimeBasedFileNamingAndTriggeringPolicyBase<E> {
29  
30    @Override
31    public void start() {
32      super.start();
33      archiveRemover = new TimeBasedArchiveRemover(tbrp.fileNamePattern, rc);
34      archiveRemover.setContext(context);
35      started = true;
36    }
37  
38    public boolean isTriggeringEvent(File activeFile, final E event) {
39      long time = getCurrentTime();
40      if (time >= nextCheck) {
41        Date dateOfElapsedPeriod = dateInCurrentPeriod;
42        addInfo("Elapsed period: "+dateOfElapsedPeriod);
43        elapsedPeriodsFileName = tbrp.fileNamePatternWCS
44            .convert(dateOfElapsedPeriod);
45        setDateInCurrentPeriod(time);
46        computeNextCheck();
47        return true;
48      } else {
49        return false;
50      }
51    }
52  
53    @Override
54    public String toString() {
55      return "c.q.l.core.rolling.DefaultTimeBasedFileNamingAndTriggeringPolicy";
56    }
57  }