001package com.credibledoc.substitution.reporting.logback;
002
003import ch.qos.logback.core.rolling.TriggeringPolicyBase;
004
005import java.io.File;
006
007/**
008 * The {@link TriggeringPolicyBase} that triggered on startup when the previous file is not empty.
009 *
010 * @param <E> this event not used in the trigger logic
011 *
012 * @author Kyrylo Semenko
013 */
014public class StartupTriggeringPolicy<E> extends TriggeringPolicyBase<E> {
015
016    private boolean isTriggeringEvent = true;
017
018    /**
019     * Return 'true' when the application launched.
020     * @param activeFile is used for the decision
021     * @param event is not used
022     * @return Return 'true' at first time. Then return 'false'.
023     */
024    public boolean isTriggeringEvent(final File activeFile, final E event) {
025        if (isTriggeringEvent) {
026            isTriggeringEvent = false;
027            // Without this condition a zero - length file has been created next to the activeFile
028            return activeFile.length() > 0;
029        }
030        return false;
031    }
032
033}