Class TimeBasedRollingPolicy<E>

  • All Implemented Interfaces:
    RollingPolicy, TriggeringPolicy<E>, ContextAware, LifeCycle
    Direct Known Subclasses:

    public class TimeBasedRollingPolicy<E>
    extends RollingPolicyBase
    implements TriggeringPolicy<E>
    TimeBasedRollingPolicy is both easy to configure and quite powerful. It allows the roll over to be made based on time. It is possible to specify that the roll over occur once per day, per week or per month.

    For more information, please refer to the online manual at

    • Constructor Detail

      • TimeBasedRollingPolicy

        public TimeBasedRollingPolicy()
    • Method Detail

      • getActiveFileName

        public String getActiveFileName()
        The active log file is determined by the value of the parent's filename option. However, in case the file name is left blank, then, the active log file equals the file name for the current period as computed by the FileNamePattern option.

        The RollingPolicy must know whether it is responsible for changing the name of the active file or not. If the active file name is set by the user via the configuration file, then the RollingPolicy must let it like it is. If the user does not specify an active file name, then the RollingPolicy generates one.

        To be sure that the file name used by the parent class has been generated by the RollingPolicy and not specified by the user, we keep track of the last generated name object and compare its reference to the parent file name. If they match, then the RollingPolicy knows it's responsible for the change of the file name.

        Specified by:
        getActiveFileName in interface RollingPolicy
      • isTriggeringEvent

        public boolean isTriggeringEvent​(File activeFile,
                                         E event)
        Description copied from interface: TriggeringPolicy
        Should roll-over be triggered at this time?
        Specified by:
        isTriggeringEvent in interface TriggeringPolicy<E>
        activeFile - A reference to the currently active log file.
        event - A reference to the currently event.
        true if a roll-over should occur.
      • getMaxHistory

        public int getMaxHistory()
        Get the number of archive files to keep.
        number of archive files to keep
      • setMaxHistory

        public void setMaxHistory​(int maxHistory)
        Set the maximum number of archive files to keep.
        maxHistory - number of archive files to keep
      • isCleanHistoryOnStart

        public boolean isCleanHistoryOnStart()
      • setCleanHistoryOnStart

        public void setCleanHistoryOnStart​(boolean cleanHistoryOnStart)
        Should archive removal be attempted on application start up? Default is false.
        cleanHistoryOnStart -
      • setTotalSizeCap

        public void setTotalSizeCap​(FileSize totalSizeCap)