001/** 002 * Logback: the reliable, generic, fast and flexible logging framework. 003 * Copyright (C) 1999-2015, 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 v1.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 java.io.File; 017import java.util.Date; 018 019import ch.qos.logback.core.joran.spi.NoAutoStart; 020import ch.qos.logback.core.rolling.helper.TimeBasedArchiveRemover; 021 022/** 023 * 024 * @author Ceki Gülcü 025 * 026 * @param <E> 027 */ 028@NoAutoStart 029public class DefaultTimeBasedFileNamingAndTriggeringPolicy<E> extends TimeBasedFileNamingAndTriggeringPolicyBase<E> { 030 031 @Override 032 public void start() { 033 super.start(); 034 if (!super.isErrorFree()) 035 return; 036 if (tbrp.fileNamePattern.hasIntegerTokenCOnverter()) { 037 addError("Filename pattern [" + tbrp.fileNamePattern 038 + "] contains an integer token converter, i.e. %i, INCOMPATIBLE with this configuration. Remove it."); 039 return; 040 } 041 042 archiveRemover = new TimeBasedArchiveRemover(tbrp.fileNamePattern, rc); 043 archiveRemover.setContext(context); 044 started = true; 045 } 046 047 public boolean isTriggeringEvent(File activeFile, final E event) { 048 long time = getCurrentTime(); 049 if (time >= nextCheck) { 050 Date dateOfElapsedPeriod = dateInCurrentPeriod; 051 addInfo("Elapsed period: " + dateOfElapsedPeriod); 052 elapsedPeriodsFileName = tbrp.fileNamePatternWithoutCompSuffix.convert(dateOfElapsedPeriod); 053 setDateInCurrentPeriod(time); 054 computeNextCheck(); 055 return true; 056 } else { 057 return false; 058 } 059 } 060 061 @Override 062 public String toString() { 063 return "c.q.l.core.rolling.DefaultTimeBasedFileNamingAndTriggeringPolicy"; 064 } 065}