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.helper;
15  
16  import java.io.File;
17  import java.util.Date;
18  
19  public class TimeBasedArchiveRemover extends DefaultArchiveRemover {
20  
21    public TimeBasedArchiveRemover(FileNamePattern fileNamePattern,
22                                   RollingCalendar rc) {
23      super(fileNamePattern, rc);
24    }
25  
26    protected void cleanByPeriodOffset(Date now, int periodOffset) {
27      Date date2delete = rc.getRelativeDate(now, periodOffset);
28      String filename = fileNamePattern.convert(date2delete);
29      File file2Delete = new File(filename);
30      if (file2Delete.exists() && file2Delete.isFile()) {
31        file2Delete.delete();
32        addInfo("deleting " + file2Delete);
33        if (parentClean) {
34          removeFolderIfEmpty(file2Delete.getParentFile());
35        }
36      }
37    }
38  
39    public String toString() {
40      return "c.q.l.core.rolling.helper.TimeBasedArchiveRemover";
41    }
42  }