Apache Log4cxx  Version 1.2.0
Loading...
Searching...
No Matches
log4cxx::rolling::FixedWindowRollingPolicy Class Reference

When rolling over, FixedWindowRollingPolicy renames files according to a fixed window algorithm as described below. More...

#include <fixedwindowrollingpolicy.h>

Inheritance diagram for log4cxx::rolling::FixedWindowRollingPolicy:
log4cxx::rolling::RollingPolicyBase log4cxx::rolling::RollingPolicy log4cxx::helpers::Object log4cxx::spi::OptionHandler log4cxx::helpers::Object

Public Member Functions

 FixedWindowRollingPolicy ()
 
 ~FixedWindowRollingPolicy ()
 
void activateOptions (helpers::Pool &p) override
 Activate the options that were previously set with calls to option setters.
 
void setOption (const LogString &option, const LogString &value) override
 Set option to value.
 
void rollover ()
 
int getMaxIndex () const
 
int getMinIndex () const
 
void setMaxIndex (int newVal)
 
void setMinIndex (int newVal)
 
RolloverDescriptionPtr initialize (const LogString &currentActiveFile, const bool append, helpers::Pool &pool) override
 Initialize the policy and return any initial actions for rolling file appender.
Parameters
currentActiveFilecurrent value of RollingFileAppender.getFile().
appendcurrent value of RollingFileAppender.getAppend().
poolpool for memory allocations during call.
Returns
Description of the initialization, may be null to indicate no initialization needed.
Exceptions
SecurityExceptionif denied access to log files.

 
RolloverDescriptionPtr rollover (const LogString &currentActiveFile, const bool append, helpers::Pool &pool) override
 Prepare for a rollover.This method is called prior to closing the active log file, performs any necessary preliminary actions and describes actions needed after close of current log file.
Parameters
currentActiveFilefile name for current active log file.
appendcurrent value of the parent FileAppender.getAppend().
poolpool for memory allocations during call.
Returns
Description of pending rollover, may be null to indicate no rollover at this time.
Exceptions
SecurityExceptionif denied access to log files.

 
- Public Member Functions inherited from log4cxx::rolling::RollingPolicyBase
 RollingPolicyBase ()
 
virtual ~RollingPolicyBase ()
 
void activateOptions (helpers::Pool &p) override
 Activate the options that were previously set with calls to option setters.
 
virtual pattern::PatternMap getFormatSpecifiers () const =0
 A map from a name to the object implementing the (date or index) formatting.
 
void setOption (const LogString &option, const LogString &value) override
 Set option to value.
 
void setFileNamePattern (const LogString &fnp)
 Set file name pattern.
 
LogString getFileNamePattern () const
 Get file name pattern.
 
bool getCreateIntermediateDirectories () const
 
void setCreateIntermediateDirectories (bool createIntermediate)
 
PatternConverterList getPatternConverterList () const
 
- Public Member Functions inherited from log4cxx::rolling::RollingPolicy
virtual ~RollingPolicy ()
 
virtual RolloverDescriptionPtr initialize (const LogString &currentActiveFile, const bool append, log4cxx::helpers::Pool &pool)=0
 Initialize the policy and return any initial actions for rolling file appender.
 
virtual RolloverDescriptionPtr rollover (const LogString &currentActiveFile, const bool append, log4cxx::helpers::Pool &pool)=0
 Prepare for a rollover.
 
- Public Member Functions inherited from log4cxx::spi::OptionHandler
virtual ~OptionHandler ()
 
virtual void activateOptions (helpers::Pool &p)=0
 Activate the options that were previously set with calls to option setters.
 
virtual void setOption (const LogString &option, const LogString &value)=0
 Set option to value.
 
- Public Member Functions inherited from log4cxx::helpers::Object
virtual ~Object ()
 
virtual const helpers::ClassgetClass () const =0
 
virtual bool instanceof (const Class &clazz) const =0
 
virtual const void * cast (const Class &clazz) const =0
 

Protected Member Functions

log4cxx::pattern::PatternMap getFormatSpecifiers () const override
 A map from "i" and "index" to a integer conversion formatter.
 
- Protected Member Functions inherited from log4cxx::rolling::RollingPolicyBase
 RollingPolicyBase (LOG4CXX_PRIVATE_PTR(RollingPolicyBasePrivate) priv)
 
void parseFileNamePattern ()
 Parse file name pattern.
 
void formatFileName (const helpers::ObjectPtr &obj, LogString &buf, helpers::Pool &p) const
 Format file name.
 
log4cxx::pattern::PatternConverterPtr getIntegerPatternConverter () const
 
log4cxx::pattern::PatternConverterPtr getDatePatternConverter () const
 

Detailed Description

When rolling over, FixedWindowRollingPolicy renames files according to a fixed window algorithm as described below.

The ActiveFileName property, which is required, represents the name of the file where current logging output will be written. The FileNamePattern option represents the file name pattern for the archived (rolled over) log files. If present, the FileNamePattern option must include an integer token, that is the string "%i" somwhere within the pattern.

Let max and min represent the values of respectively the MaxIndex and MinIndex options. Let "foo.log" be the value of the ActiveFile option and "foo.%i.log" the value of FileNamePattern. Then, when rolling over, the file foo.max.log will be deleted, the file foo.max-1.log will be renamed as foo.max.log, the file foo.max-2.log renamed as foo.max-1.log, and so on, the file foo.min+1.log renamed as foo.min+2.log. Lastly, the active file foo.log will be renamed as foo.min.log and a new active file name foo.log will be created.

Given that this rollover algorithm requires as many file renaming operations as the window size, large window sizes are discouraged. The current implementation will automatically reduce the window size to 12 when larger values are specified by the user.

Constructor & Destructor Documentation

◆ FixedWindowRollingPolicy()

log4cxx::rolling::FixedWindowRollingPolicy::FixedWindowRollingPolicy ( )

◆ ~FixedWindowRollingPolicy()

log4cxx::rolling::FixedWindowRollingPolicy::~FixedWindowRollingPolicy ( )

Member Function Documentation

◆ activateOptions()

void log4cxx::rolling::FixedWindowRollingPolicy::activateOptions ( helpers::Pool p)
overridevirtual

Activate the options that were previously set with calls to option setters.

Logs a warning if an option is not valid.

See also
RollingPolicyBase::activateOptions()

Implements log4cxx::spi::OptionHandler.

◆ getFormatSpecifiers()

log4cxx::pattern::PatternMap log4cxx::rolling::FixedWindowRollingPolicy::getFormatSpecifiers ( ) const
overrideprotectedvirtual

A map from "i" and "index" to a integer conversion formatter.

See also
IntegerPatternConverter

Implements log4cxx::rolling::RollingPolicyBase.

◆ getMaxIndex()

int log4cxx::rolling::FixedWindowRollingPolicy::getMaxIndex ( ) const

◆ getMinIndex()

int log4cxx::rolling::FixedWindowRollingPolicy::getMinIndex ( ) const

◆ initialize()

RolloverDescriptionPtr log4cxx::rolling::FixedWindowRollingPolicy::initialize ( const LogString currentActiveFile,
const bool  append,
helpers::Pool pool 
)
overridevirtual

Initialize the policy and return any initial actions for rolling file appender.

Parameters
currentActiveFilecurrent value of RollingFileAppender.getFile().
appendcurrent value of RollingFileAppender.getAppend().
poolpool for memory allocations during call.
Returns
Description of the initialization, may be null to indicate no initialization needed.
Exceptions
SecurityExceptionif denied access to log files.

Implements log4cxx::rolling::RollingPolicy.

◆ rollover() [1/2]

void log4cxx::rolling::FixedWindowRollingPolicy::rollover ( )

◆ rollover() [2/2]

RolloverDescriptionPtr log4cxx::rolling::FixedWindowRollingPolicy::rollover ( const LogString currentActiveFile,
const bool  append,
helpers::Pool pool 
)
overridevirtual

Prepare for a rollover.This method is called prior to closing the active log file, performs any necessary preliminary actions and describes actions needed after close of current log file.

Parameters
currentActiveFilefile name for current active log file.
appendcurrent value of the parent FileAppender.getAppend().
poolpool for memory allocations during call.
Returns
Description of pending rollover, may be null to indicate no rollover at this time.
Exceptions
SecurityExceptionif denied access to log files.

Implements log4cxx::rolling::RollingPolicy.

◆ setMaxIndex()

void log4cxx::rolling::FixedWindowRollingPolicy::setMaxIndex ( int  newVal)

◆ setMinIndex()

void log4cxx::rolling::FixedWindowRollingPolicy::setMinIndex ( int  newVal)

◆ setOption()

void log4cxx::rolling::FixedWindowRollingPolicy::setOption ( const LogString option,
const LogString value 
)
overridevirtual

Set option to value.

Supported options Supported values Default value
MinIndex 1-12 1
MaxIndex 1-12 7
ThrowIOExceptionOnForkFailure True,False True
See also
RollingPolicyBase::setOption()

Implements log4cxx::spi::OptionHandler.


The documentation for this class was generated from the following file: