Logback API
Version 0.9.8

ch.qos.logback.core.rolling
Class TimeBasedRollingPolicy

java.lang.Object
  extended by ch.qos.logback.core.spi.ContextAwareBase
      extended by ch.qos.logback.core.rolling.RollingPolicyBase
          extended by ch.qos.logback.core.rolling.TimeBasedRollingPolicy
All Implemented Interfaces:
RollingPolicy, TriggeringPolicy, ContextAware, LifeCycle

public class TimeBasedRollingPolicy
extends RollingPolicyBase
implements TriggeringPolicy

TimeBasedRollingPolicy is both easy to configure and quite powerful. It allows the rollover to be made based on time conditions. It is possible to specify that the rollover must occur each day, or month, for example. For more information about this policy, please refer to the online manual at http://logback.qos.ch/manual/appenders.html#TimeBasedRollingPolicy

Author:
Ceki Gülcü

Field Summary
 
Fields inherited from class ch.qos.logback.core.rolling.RollingPolicyBase
compressionMode, fileNamePattern, fileNamePatternStr
 
Fields inherited from class ch.qos.logback.core.spi.ContextAwareBase
context
 
Constructor Summary
TimeBasedRollingPolicy()
           
 
Method Summary
 long getCurrentTime()
           
 String getNewActiveFileName()
          The active log file is determined by the value of the parent's filename option.
 boolean isTriggeringEvent(File activeFile, Object event)
          Should roll-over be triggered at this time?
 void rollover()
          Rolls over log files according to implementation policy.
 void setCurrentTime(long timeInMillis)
           
 void start()
           
 String toString()
           
 
Methods inherited from class ch.qos.logback.core.rolling.RollingPolicyBase
determineCompressionMode, getFileNamePattern, getParentFileName, isStarted, setFileNamePattern, setParent, setParentFileName, stop
 
Methods inherited from class ch.qos.logback.core.spi.ContextAwareBase
addError, addError, addInfo, addInfo, addStatus, addWarn, addWarn, getContext, getStatusManager, setContext
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface ch.qos.logback.core.spi.LifeCycle
isStarted, stop
 

Constructor Detail

TimeBasedRollingPolicy

public TimeBasedRollingPolicy()
Method Detail

setCurrentTime

public void setCurrentTime(long timeInMillis)

getCurrentTime

public long getCurrentTime()

start

public void start()
Specified by:
start in interface LifeCycle
Overrides:
start in class RollingPolicyBase

rollover

public void rollover()
              throws RolloverFailure
Description copied from interface: RollingPolicy
Rolls over log files according to implementation policy.

This method is invoked by RollingFileAppender, usually at the behest of its TriggeringPolicy.

Specified by:
rollover in interface RollingPolicy
Throws:
RolloverFailure - Thrown if the rollover operation fails for any reason.

getNewActiveFileName

public String getNewActiveFileName()
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 wether 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:
getNewActiveFileName in interface RollingPolicy

isTriggeringEvent

public boolean isTriggeringEvent(File activeFile,
                                 Object event)
Description copied from interface: TriggeringPolicy
Should roll-over be triggered at this time?

Specified by:
isTriggeringEvent in interface TriggeringPolicy
Parameters:
activeFile - A reference to the currently active log file.
event - A reference to the currently event.
Returns:
true if a roll-over should occur.

toString

public String toString()
Overrides:
toString in class Object

Logback API
Version 0.9.8

Copyright © 2005-2008 QOS.ch. All Rights Reserved.