Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Logback: the reliable, generic, fast and flexible logging framework. Copyright (C) 1999-2011, QOS.ch. All rights reserved. This program and the accompanying materials are dual-licensed under either the terms of the Eclipse Public License v1.0 as published by the Eclipse Foundation or (per the licensee's choosing) under the terms of the GNU Lesser General Public License version 2.1 as published by the Free Software Foundation.
 
 package ch.qos.logback.core.rolling;
 
 import java.io.File;
 import java.util.Date;
 
When rolling over, FixedWindowRollingPolicy renames files according to a fixed window algorithm. For more information about this policy, please refer to the online manual at http://logback.qos.ch/manual/appenders.html#FixedWindowRollingPolicy

Author(s):
Ceki Gülcü
 
 public class FixedWindowRollingPolicy extends RollingPolicyBase {
   static final String FNP_NOT_SET = "The \"FileNamePattern\" property must be set before using FixedWindowRollingPolicy. ";
   static final String PRUDENT_MODE_UNSUPPORTED = "See also http://logback.qos.ch/codes.html#tbr_fnp_prudent_unsupported";
   static final String SEE_PARENT_FN_NOT_SET = "Please refer to http://logback.qos.ch/codes.html#fwrp_parentFileName_not_set";
   int maxIndex;
   int minIndex;
   RenameUtil util = new RenameUtil();
 
   public static final String ZIP_ENTRY_DATE_PATTERN = "yyyy-MM-dd_HHmm";

  
It's almost always a bad idea to have a large window size, say over 12.
 
   private static int MAX_WINDOW_SIZE = 12;
 
   public FixedWindowRollingPolicy() {
      = 1;
      = 7;
   }
 
   public void start() {
     .setContext(this.);
    
     if ( != null) {
     } else {
       addError();
     }
 
     if(isParentPrudent()) {
       addError("Prudent mode is not supported with FixedWindowRollingPolicy.");
       throw new IllegalStateException("Prudent mode is not supported.");
     }
     
     if (getParentsRawFileProperty() == null) {
       addError("The File name property must be set before using this rolling policy.");
       throw new IllegalStateException("The \"File\" option must be set.");
     }
 
     if ( < ) {
       addWarn("MaxIndex (" +  + ") cannot be smaller than MinIndex ("
           +  + ").");
       addWarn("Setting maxIndex to equal minIndex.");
        = ;
     }
 
     if (( - ) > ) {
       addWarn("Large window sizes are not allowed.");
        =  + ;
       addWarn("MaxIndex reduced to " + );
     }
 
 
     if (itc == null) {
       throw new IllegalStateException("FileNamePattern ["
           + .getPattern()
           + "] does not contain a valid IntegerToken");
     }
 
     if( == .) {
       String zipEntryFileNamePatternStr = transformFileNamePatternFromInt2Date();
        = new FileNamePattern(zipEntryFileNamePatternStr);
    }
    super.start();
  }
  private String transformFileNamePatternFromInt2Date(String fileNamePatternStr) {
    String slashified = FileFilterUtil.slashify(fileNamePatternStr);
    String stemOfFileNamePattern = FileFilterUtil.afterLastSlash(slashified);
    return stemOfFileNamePattern.replace("%i""%d{"++"}");
  }
  public void rollover() throws RolloverFailure {
    // Inside this method it is guaranteed that the hereto active log file is
    // closed.
    // If maxIndex <= 0, then there is no file renaming to be done.
    if ( >= 0) {
      // Delete the oldest file, to keep Windows happy.
      File file = new File(.convertInt());
      if (file.exists()) {
        file.delete();
      }
      // Map {(maxIndex - 1), ..., minIndex} to {maxIndex, ..., minIndex+1}
      for (int i =  - 1; i >= i--) {
        String toRenameStr = .convertInt(i);
        File toRename = new File(toRenameStr);
        // no point in trying to rename an inexistent file
        if (toRename.exists()) {
          .rename(toRenameStr.convertInt(i + 1));
        } else {
          addInfo("Skipping roll-over for inexistent file " + toRenameStr);
        }
      }
      // move active file name to min
      switch () {
      case :
            .convertInt());
        break;
      case :
        break;
      case :
        break;
      }
    }
  }

  
Return the value of the parent's RawFile property.
  public String getActiveFileName() {
    return getParentsRawFileProperty();
  }
  public int getMaxIndex() {
    return ;
  }
  public int getMinIndex() {
    return ;
  }
  public void setMaxIndex(int maxIndex) {
    this. = maxIndex;
  }
  public void setMinIndex(int minIndex) {
    this. = minIndex;
  }
New to GrepCode? Check out our FAQ X