Uploaded image for project: 'logback'
  1. logback
  2. LOGBACK-221

Add new TriggeringPolicy class to cause one rollover at the start of each run

    Details

    • Type: New Feature
    • Status: Resolved
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: logback-core
    • Labels:
      None
    • Environment:

      -

      Description

      A new TriggeringPolicy will cause the logfile to rollover once at startup when used with FixedWindowRollingPolicy. This is useful during development so that the logfiles of recent runs are still available. Here is a candidate implementation. Note that

      • <append>true</append> is required - otherwise the previous file is overwritten before rollover happens, so rollover results in a useless list of empty files.
      • the documentation would need to warn users of the effect of running multiple applications concurrently (i.e. concurrent operating system processes) with the same logfiles. This applies even without the suggested feature.

      package ch.qos.logback.core.rolling;

      import java.io.File;

      import ch.qos.logback.core.rolling.TriggeringPolicyBase;

      /**

      • SimpleStartupTriggeringPolicy triggers a rollover once at startup only. This
      • is useful for preserving older logfiles during development.
      • @author Rick Beton
        */
        public final class SimpleStartupTriggeringPolicy<E> extends TriggeringPolicyBase<E> {

      private boolean fired = false;

      public SimpleStartupTriggeringPolicy ()

      { // does nothing }

      public boolean isTriggeringEvent( final File activeFile, final E event ) {
      final boolean result = !fired && (activeFile.length() > 0);
      fired = true;
      if (result)

      { addInfo( "Triggering rollover for " + activeFile ); }

      return result;
      }
      }

        Attachments

          Activity

            People

            • Assignee:
              ceki Ceki Gülcü
              Reporter:
              rickb Rick Beton
            • Votes:
              2 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: