carnold 2005/01/06 17:25:20
Modified: include/log4cxx Makefile.am rollingfileappender.h
tests/src Makefile.am
Added: include/log4cxx/rolling Makefile.am
fixedwindowrollingpolicy.h rollingfileappender.h
rollingpolicy.h rollingpolicybase.h
rolloverfailure.h sizebasedtriggeringpolicy.h
timebasedrollingpolicy.h triggeringpolicy.h
tests/src/rolling Makefile.am timebasedrollingtest.cpp
Log:
LOGCXX-52: log4j 1.3 RollingFA migration: headers only
Revision Changes Path
1.7 +1 -1 logging-log4cxx/include/log4cxx/Makefile.am
Index: Makefile.am
===================================================================
RCS file: /home/cvs/logging-log4cxx/include/log4cxx/Makefile.am,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- Makefile.am 16 Aug 2004 09:41:51 -0000 1.6
+++ Makefile.am 7 Jan 2005 01:25:19 -0000 1.7
@@ -1,4 +1,4 @@
-SUBDIRS = helpers net nt spi varia xml config db
+SUBDIRS = helpers net nt rolling spi varia xml config db
log4cxxincdir = $(includedir)/log4cxx
log4cxxinc_HEADERS= $(top_srcdir)/include/log4cxx/*.h config_auto_log4cxx.h
DISTCLEANFILES = config_auto_log4cxx.h
1.15 +5 -1 logging-log4cxx/include/log4cxx/rollingfileappender.h
Index: rollingfileappender.h
===================================================================
RCS file: /home/cvs/logging-log4cxx/include/log4cxx/rollingfileappender.h,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- rollingfileappender.h 26 Dec 2004 07:31:52 -0000 1.14
+++ rollingfileappender.h 7 Jan 2005 01:25:19 -0000 1.15
@@ -21,7 +21,11 @@
#include <log4cxx/helpers/optionconverter.h>
namespace log4cxx
-{
+{
+
+ class RollingFileAppender;
+ typedef log4cxx::helpers::ObjectPtrT<RollingFileAppender>
RollingFileAppenderPtr;
+
/**
RollingFileAppender extends FileAppender to backup the log files when
they reach a certain size.
1.1 logging-log4cxx/include/log4cxx/rolling/Makefile.am
Index: Makefile.am
===================================================================
rollingincdir = $(includedir)/log4cxx/rolling
rollinginc_HEADERS= $(top_srcdir)/include/log4cxx/rolling/*.h
1.1
logging-log4cxx/include/log4cxx/rolling/fixedwindowrollingpolicy.h
Index: fixedwindowrollingpolicy.h
===================================================================
/*
* Copyright 1999,2005 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#if !defined(_LOG4CXX_ROLLING_FIXED_WINDOW_ROLLING_POLICY_H)
#define _LOG4CXX_ROLLING_FIXED_WINDOW_ROLLING_POLICY_H
#include <log4cxx/portability.h>
#include <log4cxx/rolling/rollingpolicybase.h>
/**
* When rolling over, <code>FixedWindowRollingPolicy</code> renames files
* according to a fixed window algorithm as described below.
*
* <p>The <b>ActiveFileName</b> property, which is required, represents the
name
* of the file where current logging output will be written.
* The <b>FileNamePattern</b> option represents the file name pattern for
the
* archived (rolled over) log files. If present, the <b>FileNamePattern</b>
* option must include an integer token, that is the string "%i" somwhere
* within the pattern.
*
* <p>Let <em>max</em> and <em>min</em> represent the values of respectively
* the <b>MaxIndex</b> and <b>MinIndex</b> options. Let "foo.log" be the value
* of the <b>ActiveFile</b> option and "foo.%i.log" the value of
* <b>FileNamePattern</b>. Then, when rolling over, the file
* <code>foo.<em>max</em>.log</code> will be deleted, the file
* <code>foo.<em>max-1</em>.log</code> will be renamed as
* <code>foo.<em>max</em>.log</code>, the file
<code>foo.<em>max-2</em>.log</code>
* renamed as <code>foo.<em>max-1</em>.log</code>, and so on,
* the file <code>foo.<em>min+1</em>.log</code> renamed as
* <code>foo.<em>min+2</em>.log</code>. Lastly, the active file
<code>foo.log</code>
* will be renamed as <code>foo.<em>min</em>.log</code> and a new active file
name
* <code>foo.log</code> will be created.
*
* <p>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.
*
*
* @author Ceki Gülcü
* @since 1.3
* */
namespace log4cxx {
namespace rolling {
class LOG4CXX_EXPORT FixedWindowRollingPolicy : public
RollingPolicyBase {
private:
int maxIndex;
int minIndex;
/**
* It's almost always a bad idea to have a large window size, say
over 12.
*/
static int MAX_WINDOW_SIZE;
public:
FixedWindowRollingPolicy();
void activateOptions();
void rollover();
inline int getMaxIndex() const {
return maxIndex;
}
inline int getMinIndex() const {
return minIndex;
}
void setMaxIndex(int newVal);
void setMinIndex(int newVal);
};
typedef log4cxx::helpers::ObjectPtrT<FixedWindowRollingPolicy>
FixedWindowRollingPolicyPtr;
}
}
#endif
1.1
logging-log4cxx/include/log4cxx/rolling/rollingfileappender.h
Index: rollingfileappender.h
===================================================================
/*
* Copyright 1999,2005 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#if !defined(_LOG4CXX_ROLLING_ROLLING_FILE_APPENDER_H)
#define _LOG4CXX_ROLLING_ROLLING_FILE_APPENDER_H
#include <log4cxx/portability.h>
#include <log4cxx/spi/optionhandler.h>
#include <log4cxx/fileappender.h>
#include <log4cxx/rolling/triggeringpolicy.h>
#include <log4cxx/rolling/rollingpolicy.h>
namespace log4cxx {
namespace rolling {
/**
* <code>RollingFileAppender</code> extends [EMAIL PROTECTED]
FileAppender} to backup the log files
* depending on [EMAIL PROTECTED] RollingPolicy} and [EMAIL
PROTECTED] TriggeringPolicy}.
* <p>
* To be of any use, a <code>RollingFileAppender</code> instance must
have both
* a <code>RollingPolicy</code> and a <code>TriggeringPolicy</code>
set up.
* However, if its <code>RollingPolicy</code> also implements the
* <code>TriggeringPolicy</code> interface, then only the former
needs to be
* set up. For example, [EMAIL PROTECTED] TimeBasedRollingPolicy}
acts both as a
* <code>RollingPolicy</code> and a <code>TriggeringPolicy</code>.
*
* <p><code>RollingFileAppender</code> can be configured
programattically or
* using [EMAIL PROTECTED] org.apache.log4j.joran.JoranConfigurator}.
Here is a sample
* configration file:
<pre><?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration>
<log4j:configuration debug="true">
<appender name="ROLL"
class="org.apache.log4j.rolling.RollingFileAppender">
<b><rollingPolicy
class="org.apache.log4j.rolling.TimeBasedRollingPolicy">
<param name="FileNamePattern"
value="/wombat/foo.%d{yyyy-MM}.gz"/>
</rollingPolicy></b>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%c{1} - %m%n"/>
</layout>
</appender>
<root">
<appender-ref ref="ROLL"/>
</root>
</log4j:configuration>
</pre>
*<p>This configuration file specifies a monthly rollover schedule
including
* automatic compression of the archived files. See
* [EMAIL PROTECTED] TimeBasedRollingPolicy} for more details.
*
* @author Heinz Richter
* @author Ceki Gülcü
* @since 1.3
* */
class LOG4CXX_EXPORT RollingFileAppender : public FileAppender {
private:
File activeFile;
TriggeringPolicyPtr triggeringPolicy;
RollingPolicyPtr rollingPolicy;
public:
/**
* The default constructor simply calls its [EMAIL PROTECTED]
* FileAppender#FileAppender parents constructor}.
* */
RollingFileAppender();
void activateOptions(log4cxx::helpers::Pool&);
/**
Implements the usual roll over behaviour.
<p>If <code>MaxBackupIndex</code> is positive, then files
{<code>File.1</code>, ..., <code>File.MaxBackupIndex -1</code>}
are renamed to {<code>File.2</code>, ...,
<code>File.MaxBackupIndex</code>}. Moreover, <code>File</code> is
renamed <code>File.1</code> and closed. A new <code>File</code>
is
created to receive further log output.
<p>If <code>MaxBackupIndex</code> is equal to zero, then the
<code>File</code> is truncated with no backup files created.
*/
void rollover();
protected:
/**
This method differentiates RollingFileAppender from its super
class.
*/
void subAppend(log4cxx::spi::LoggingEvent& event);
public:
const RollingPolicyPtr& getRollingPolicy() const;
const TriggeringPolicyPtr& getTriggeringPolicy() const;
/**
* Sets the rolling policy. In case the 'policy' argument also
implements
* [EMAIL PROTECTED] TriggeringPolicy}, then the triggering policy
for this appender
* is automatically set to be the policy argument.
* @param policy
*/
void setRollingPolicy(const RollingPolicyPtr& policy);
void setTriggeringPolicy(const TriggeringPolicyPtr& policy);
};
typedef log4cxx::helpers::ObjectPtrT<RollingFileAppender>
RollingFileAppenderPtr;
}
}
#endif
1.1 logging-log4cxx/include/log4cxx/rolling/rollingpolicy.h
Index: rollingpolicy.h
===================================================================
/*
* Copyright 1999,2005 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#if !defined(_LOG4CXX_ROLLING_ROLLING_POLICY_H)
#define _LOG4CXX_ROLLING_ROLLING_POLICY_H
#include <log4cxx/portability.h>
#include <log4cxx/spi/optionhandler.h>
#include <log4cxx/file.h>
namespace log4cxx {
namespace rolling {
/**
* A <code>RollingPolicy</code> is responsible for performing the
* rolling over of the active log file. The <code>RollingPolicy</code>
* is also responsible for providing the <em>active log file</em>,
* that is the live file where logging output will be directed.
*
* @author Ceki Gülcü
* @since 1.3
*
*/
class LOG4CXX_EXPORT RollingPolicy : public
log4cxx::spi::OptionHandler {
public:
/**
* Rolls over log files according to implementation policy.
* <p>
* <p>This method is invoked by [EMAIL PROTECTED]
RollingFileAppender}, usually
* at the behest of its [EMAIL PROTECTED] TriggeringPolicy}.
*
* @throws RolloverFailure Thrown if the rollover operation
fails for any
* reason.
*/
virtual void rollover() = 0;
/**
* Get the new name of the active log file.
* */
virtual log4cxx::File getActiveFileName() = 0;
};
typedef log4cxx::helpers::ObjectPtrT<RollingPolicy> RollingPolicyPtr;
}
}
#endif
1.1
logging-log4cxx/include/log4cxx/rolling/rollingpolicybase.h
Index: rollingpolicybase.h
===================================================================
/*
* Copyright 1999,2005 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#if !defined(_LOG4CXX_ROLLING_ROLLING_POLICY_BASE_H)
#define _LOG4CXX_ROLLING_ROLLING_POLICY_BASE_H
#include <log4cxx/logger.h>
#include <log4cxx/logmanager.h>
#include <log4cxx/rolling/rollingpolicy.h>
namespace log4cxx {
namespace rolling {
typedef LogString FileNamePattern;
/**
* Implements methods common to most, it not all, rolling
* policies. Currently such methods are limited to a compression mode
* getter/setter.
*
* @author Ceki Gülcü
* @since 1.3
*/
class RollingPolicyBase : public virtual RollingPolicy,
public virtual log4cxx::helpers::ObjectImpl
{
protected:
int compressionMode;
FileNamePattern fileNamePattern;
LogString fileNamePatternStr;
File activeFileName;
public:
BEGIN_LOG4CXX_CAST_MAP()
LOG4CXX_CAST_ENTRY(RollingPolicyBase)
LOG4CXX_CAST_ENTRY(spi::OptionHandler)
END_LOG4CXX_CAST_MAP()
virtual void activateOptions(log4cxx::helpers::Pool& pool) {}
virtual void setOption(const LogString& option, const LogString&
value);
protected:
/**
* Given the FileNamePattern string, this method determines the
compression
* mode depending on last letters of the fileNamePatternStr.
Patterns
* ending with .gz imply GZIP compression, endings with '.zip' imply
* ZIP compression. Otherwise and by default, there is no
compression.
*
*/
void determineCompressionMode();
public:
void setFileNamePattern(const LogString& fnp);
LogString getFileNamePattern() const;
/**
* ActiveFileName can be left unset, i.e. as null.
* @see #getActiveFileName
*/
void setActiveFileName(const File& afn);
};
}
}
#endif
1.1 logging-log4cxx/include/log4cxx/rolling/rolloverfailure.h
Index: rolloverfailure.h
===================================================================
/*
* Copyright 1999,2005 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#if !defined(_LOG4CXX_ROLLING_ROLLOVER_FAILURE_H)
#define _LOG4CXX_ROLLING_ROLLOVER_FAILURE_H
#include <log4cxx/helpers/exception.h>
namespace log4cxx {
namespace rolling {
/**
* A RolloverFailure occurs if, for whatever reason a rollover fails.
*
* @author Ceki Gulcu
*/
class LOG4CXX_EXPORT RolloverFailure : public
log4cxx::helpers::Exception {
public:
RolloverFailure(const LogString& msg);
RolloverFailure(const RolloverFailure& src);
RolloverFailure& operator=(const RolloverFailure& src);
};
}
}
#endif
1.1
logging-log4cxx/include/log4cxx/rolling/sizebasedtriggeringpolicy.h
Index: sizebasedtriggeringpolicy.h
===================================================================
/*
* Copyright 1999,2005 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#if !defined(_LOG4CXX_ROLLING_SIZE_BASED_TRIGGERING_POLICY_H)
#define _LOG4CXX_ROLLING_SIZE_BASED_TRIGGERING_POLICY_H
#include <log4cxx/portability.h>
#include <log4cxx/rolling/triggeringpolicy.h>
namespace log4cxx {
class File;
namespace rolling {
/**
* SizeBasedTriggeringPolicy looks at size of the file being
* currently written to.
*
* @author Ceki Gülcü
*
*/
class LOG4CXX_EXPORT SizeBasedTriggeringPolicy : public
TriggeringPolicy {
protected:
long maxFileSize;
public:
bool isTriggeringEvent(const log4cxx::File& file);
size_t getMaxFileSize();
void setMaxFileSize(size_t l);
void activateOptions();
};
typedef log4cxx::helpers::ObjectPtrT<SizeBasedRollingPolicy>
SizeBasedRollingPolicyPtr;
}
}
#endif
1.1
logging-log4cxx/include/log4cxx/rolling/timebasedrollingpolicy.h
Index: timebasedrollingpolicy.h
===================================================================
/*
* Copyright 1999,2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#if !defined(_LOG4CXX_ROLLING_TIME_BASED_ROLLING_POLICY_H)
#define _LOG4CXX_ROLLING_TIME_BASED_ROLLING_POLICY_H
#include <log4cxx/portability.h>
#include <log4cxx/rolling/rollingpolicybase.h>
#include <log4cxx/rolling/triggeringpolicy.h>
namespace log4cxx {
namespace rolling {
/**
* <code>TimeBasedRollingPolicy</code> is both easy to configure and
quite
* powerful.
*
* <p>In order to use <code>TimeBasedRollingPolicy</code>, the
* <b>FileNamePattern</b> option must be set. It basically specifies
the name of the
* rolled log files. The value <code>FileNamePattern</code> should
consist of
* the name of the file, plus a suitably placed <code>%d</code>
conversion
* specifier. The <code>%d</code> conversion specifier may contain a
date and
* time pattern as specified by the [EMAIL PROTECTED]
java.text.SimpleDateFormat} class. If
* the date and time pattern is ommitted, then the default pattern of
* "yyyy-MM-dd" is assumed. The following examples should clarify the
point.
*
* <p>
* <table cellspacing="5px" border="1">
* <tr>
* <th><code>FileNamePattern</code> value</th>
* <th>Rollover schedule</th>
* <th>Example</th>
* </tr>
* <tr>
* <td nowrap="true"><code>/wombat/folder/foo.%d</code></td>
* <td>Daily rollover (at midnight). Due to the omission of the
optional
* time and date pattern for the %d token specifier, the
default pattern
* of "yyyy-MM-dd" is assumed, which corresponds to daily
rollover.
* </td>
* <td>During November 23rd, 2004, logging output will go to
* the file <code>/wombat/foo.2004-11-23</code>. At midnight
and for
* the rest of the 24th, logging output will be directed to
* <code>/wombat/foo.2004-11-24</code>.
* </td>
* </tr>
* <tr>
* <td nowrap="true"><code>/wombat/foo.%d{yyyy-MM}.log</code></td>
* <td>Rollover at the beginning of each month.</td>
* <td>During the month of October 2004, logging output will go to
* <code>/wombat/foo.2004-10.log</code>. After midnight of
October 31st
* and for the rest of November, logging output will be directed
to
* <code>/wombat/foo.2004-11.log</code>.
* </td>
* </tr>
* </table>
* <h2>Automatic file compression</h2>
* <code>TimeBasedRollingPolicy</code> supports automatic file
compression.
* This feature is enabled if the value of the <b>FileNamePattern</b>
option
* ends with <code>.gz</code> or <code>.zip</code>.
* <p>
* <table cellspacing="5px" border="1">
* <tr>
* <th><code>FileNamePattern</code> value</th>
* <th>Rollover schedule</th>
* <th>Example</th>
* </tr>
* <tr>
* <td nowrap="true"><code>/wombat/foo.%d.gz</code></td>
* <td>Daily rollover (at midnight) with automatic GZIP
compression of the
* arcived files.</td>
* <td>During November 23rd, 2004, logging output will go to
* the file <code>/wombat/foo.2004-11-23</code>. However, at
midnight that
* file will be compressed to become
<code>/wombat/foo.2004-11-23.gz</code>.
* For the 24th of November, logging output will be directed to
* <code>/wombat/folder/foo.2004-11-24</code> until its rolled
over at the
* beginning of the next day.
* </td>
* </tr>
* </table>
*
* <h2>Decoupling the location of the active log file and the
archived log files</h2>
* <p>The <em>active file</em> is defined as the log file for the
current period
* whereas <em>archived files</em> are thos files which have been
rolled over
* in previous periods.
*
* <p>By setting the <b>ActiveFileName</b> option you can decouple
the location
* of the active log file and the location of the archived log files.
* <p>
* <table cellspacing="5px" border="1">
* <tr>
* <th><code>FileNamePattern</code> value</th>
* <th>ActiveFileName</th>
* <th>Rollover schedule</th>
* <th>Example</th>
* </tr>
* <tr>
* <td nowrap="true"><code>/wombat/foo.log.%d</code></td>
* <td nowrap="true"><code>/wombat/foo.log</code></td>
* <td>Daily rollover.</td>
*
* <td>During November 23rd, 2004, logging output will go to
* the file <code>/wombat/foo.log</code>. However, at midnight
that file
* will archived as <code>/wombat/foo.log.2004-11-23</code>.
For the 24th
* of November, logging output will be directed to
* <code>/wombat/folder/foo.log</code> until its archived as
* <code>/wombat/foo.log.2004-11-24</code> at the beginning of
the next
* day.
* </td>
* </tr>
* </table>
* <p>
* If configuring programatically, do not forget to call [EMAIL
PROTECTED] #activateOptions}
* method before using this policy. Moreover, [EMAIL PROTECTED]
#activateOptions} of
* <code> TimeBasedRollingPolicy</code> must be called
<em>before</em> calling
* the [EMAIL PROTECTED] #activateOptions} method of the owning
* <code>RollingFileAppender</code>.
*
* @author Ceki Gülcü
* @since 1.3
*/
class LOG4CXX_EXPORT TimeBasedRollingPolicy : public
RollingPolicyBase {
private:
// RollingCalendar rc;
log4cxx_time_t nextCheck;
log4cxx_time_t lastCheck;
File elapsedPeriodsFileName;
FileNamePattern activeFileNamePattern;
public:
void activateOptions(log4cxx::helpers::Pool& );
void rollover();
/**
*
* The active log file is determined by the value of the
activeFileName
* option if it is set. However, in case the activeFileName is
left blank,
* then, the active log file equals the file name for the current
period
* as computed by the <b>FileNamePattern</b> option.
*
*/
File getActiveFileName();
bool isTriggeringEvent(const File& file);
};
typedef log4cxx::helpers::ObjectPtrT<TimeBasedRollingPolicy>
TimeBasedRollingPolicyPtr;
}
}
#endif
1.1
logging-log4cxx/include/log4cxx/rolling/triggeringpolicy.h
Index: triggeringpolicy.h
===================================================================
/*
* Copyright 1999,2005 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#if !defined(_LOG4CXX_ROLLING_TRIGGER_POLICY_H)
#define _LOG4CXX_ROLLING_TRIGGER_POLICY_H
#include <log4cxx/helpers/object.h>
namespace log4cxx {
class File;
namespace rolling {
/**
* A <code>TriggeringPolicy</code> controls the conditions under
which rollover
* occurs. Such conditions include time od day, file size, an
* external event or a combination thereof.
*
* @author Ceki Gülcü
* @since 1.3
* */
class LOG4CXX_EXPORT TriggeringPolicy : public
log4cxx::helpers::Object {
/**
* Should rolllover be triggered at this time?
*
* @param file A reference to the currently active log file.
* */
virtual bool isTriggeringEvent(const log4cxx::File& file) = 0;
};
typedef log4cxx::helpers::ObjectPtrT<TriggeringPolicy>
TriggeringPolicyPtr;
}
}
#endif
1.12 +1 -1 logging-log4cxx/tests/src/Makefile.am
Index: Makefile.am
===================================================================
RCS file: /home/cvs/logging-log4cxx/tests/src/Makefile.am,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- Makefile.am 2 Jan 2005 05:40:05 -0000 1.11
+++ Makefile.am 7 Jan 2005 01:25:20 -0000 1.12
@@ -1,4 +1,4 @@
-SUBDIRS = customlogger defaultinit helpers net pattern util varia db xml nt
+SUBDIRS = customlogger defaultinit helpers net pattern rolling util varia db
xml nt
EXTRA_DIST = $(top_srcdir)/tests/src/*.cpp
noinst_HEADERS= $(top_srcdir)/tests/src/*.h
1.1 logging-log4cxx/tests/src/rolling/Makefile.am
Index: Makefile.am
===================================================================
EXTRA_DIST = *.cpp
if TESTS
noinst_LIBRARIES = librolling.a
INCLUDES = -I$(top_srcdir)/include
librolling_a_SOURCES = \
timebasedrollingtest.cpp \
check: librolling.a
endif
1.1
logging-log4cxx/tests/src/rolling/timebasedrollingtest.cpp
Index: timebasedrollingtest.cpp
===================================================================
/*
* Copyright 1999,2005 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#if 0
#include <cppunit/TestFixture.h>
#include <cppunit/extensions/HelperMacros.h>
#include <log4cxx/rolling/rollingfileappender.h>
#include <log4cxx/logger.h>
#include <log4cxx/consoleappender.h>
#include <log4cxx/logmanager.h>
#include <log4cxx/patternlayout.h>
#include <log4cxx/rolling/timebasedrollingpolicy.h>
#include <log4cxx/helpers/simpledateformat.h>
#include <apr_time.h>
#include <iostream>
#include <log4cxx/helpers/stringhelper.h>
#include "../util/compare.h"
using namespace log4cxx;
using namespace log4cxx::helpers;
using namespace log4cxx::rolling;
/**
* A rather exhaustive set of tests. Tests include leaving the ActiveFileName
* argument blank, or setting it, with and without compression, and tests
* with or without stopping/restarting the RollingFileAppender.
*
* The regression tests log a few times using a RollingFileAppender. Then,
* they predict the names of the files which sould be generated and compare
* them with witness files.
*
* <pre>
Compression ActiveFileName Stop/Restart
Test1 NO BLANK NO
Test2 NO BLANK YES
Test3 YES BLANK NO
Test4 NO SET YES
Test5 NO SET NO
Test6 YES SET NO
* </pre>
* @author Ceki Gülcü
*/
class TimeBasedRollingTest : public CppUnit::TestFixture {
CPPUNIT_TEST_SUITE(TimeBasedRollingTest);
CPPUNIT_TEST_SUITE_END();
static LoggerPtr logger;
public:
void setUp() {
LoggerPtr root(Logger::getRootLogger());
root->addAppender(
new ConsoleAppender(new PatternLayout(
LOG4CXX_STR("%d{ABSOLUTE} [%t] %level %c{2}#%M:%L - %m%n"))));
}
void tearDown() {
LogManager::shutdown();
}
/**
* Test rolling without compression, activeFileName left blank, no
stop/start
*/
void test1() {
PatternLayoutPtr layout(new PatternLayout(LOG4CXX_STR("%c{1} - %m%n")));
RollingFileAppenderPtr rfa(new RollingFileAppender());
rfa->setLayout(layout);
LogString datePattern(LOG4CXX_STR("yyyy-MM-dd_HH_mm_ss"));
TimeBasedRollingPolicyPtr tbrp(new TimeBasedRollingPolicy());
tbrp->setFileNamePattern(LOG4CXX_STR("output/test1-%d{yyyy-MM-dd_HH_mm_ss}"));
Pool p;
tbrp->activateOptions(p);
rfa->setRollingPolicy(tbrp);
rfa->activateOptions(p);
logger->addAppender(rfa);
SimpleDateFormat sdf(datePattern);
LogString filenames[4];
Pool pool;
apr_time_t now = apr_time_now();
{ for (int i = 0; i < 4; i++) {
sdf.format(filenames[i], now, p);
now += APR_USEC_PER_SEC;
} }
std::cout << "Waiting until next second and 100 millis.";
delayUntilNextSecond(100);
std::cout << "Done waiting.";
{ for (int i = 0; i < 5; i++) {
std::string message("Hello---");
StringHelper::toString(i, pool, message);
LOG4CXX_DEBUG(logger, message);
apr_sleep(500000);
} }
std::ostringstream os;
for (int i = 0; i < 4; i++) {
os.str("witness/rolling/tbr-test1.");
os << i;
CPPUNIT_ASSERT(Compare::compare(filenames[i], File(os.str())));
}
}
#if 0
/**
* No compression, with stop/restart, activeFileName left blank
*/
public void test2() throws Exception {
String datePattern = "yyyy-MM-dd_HH_mm_ss";
PatternLayout layout1 = new PatternLayout("%c{1} - %m%n");
RollingFileAppender rfa1 = new RollingFileAppender();
rfa1.setLayout(layout1);
TimeBasedRollingPolicy tbrp1 = new TimeBasedRollingPolicy();
tbrp1.setFileNamePattern("output/test2-%d{" + datePattern + "}");
tbrp1.activateOptions();
rfa1.setRollingPolicy(tbrp1);
rfa1.activateOptions();
logger.addAppender(rfa1);
SimpleDateFormat sdf = new SimpleDateFormat(datePattern);
String[] filenames = new String[4];
Calendar cal = Calendar.getInstance();
for (int i = 0; i < 4; i++) {
filenames[i] = "output/test2-" + sdf.format(cal.getTime());
cal.add(Calendar.SECOND, 1);
}
System.out.println("Waiting until next second and 100 millis.");
delayUntilNextSecond(100);
System.out.println("Done waiting.");
for (int i = 0; i <= 2; i++) {
logger.debug("Hello---" + i);
Thread.sleep(500);
}
logger.removeAppender(rfa1);
rfa1.close();
PatternLayout layout2 = new PatternLayout("%c{1} - %m%n");
RollingFileAppender rfa2 = new RollingFileAppender();
rfa2.setLayout(layout2);
TimeBasedRollingPolicy tbrp2 = new TimeBasedRollingPolicy();
tbrp2.setFileNamePattern("output/test2-%d{" + datePattern + "}");
tbrp2.activateOptions();
rfa2.setRollingPolicy(tbrp2);
rfa2.activateOptions();
logger.addAppender(rfa2);
for (int i = 3; i <= 4; i++) {
logger.debug("Hello---" + i);
Thread.sleep(500);
}
for (int i = 0; i < 4; i++) {
assertTrue(Compare.compare(filenames[i], "witness/rolling/tbr-test2." +
i));
}
}
/**
* With compression, activeFileName left blank, no stop/restart
*/
public void test3() throws Exception {
PatternLayout layout = new PatternLayout("%c{1} - %m%n");
RollingFileAppender rfa = new RollingFileAppender();
rfa.setLayout(layout);
String datePattern = "yyyy-MM-dd_HH_mm_ss";
TimeBasedRollingPolicy tbrp = new TimeBasedRollingPolicy();
tbrp.setFileNamePattern("output/test3-%d{" + datePattern + "}.gz");
tbrp.activateOptions();
rfa.setRollingPolicy(tbrp);
rfa.activateOptions();
logger.addAppender(rfa);
SimpleDateFormat sdf = new SimpleDateFormat(datePattern);
String[] filenames = new String[4];
Calendar cal = Calendar.getInstance();
for (int i = 0; i < 3; i++) {
filenames[i] = "output/test3-" + sdf.format(cal.getTime()) + ".gz";
cal.add(Calendar.SECOND, 1);
}
filenames[3] = "output/test3-" + sdf.format(cal.getTime());
System.out.println("Waiting until next second and 100 millis.");
delayUntilNextSecond(100);
System.out.println("Done waiting.");
for (int i = 0; i < 5; i++) {
logger.debug("Hello---" + i);
Thread.sleep(500);
}
for (int i = 0; i < 4; i++) {
//System.out.println(i + " expected filename [" + filenames[i] + "].");
}
for (int i = 0; i < 3; i++) {
assertTrue(Compare.gzCompare(filenames[i], "witness/rolling/tbr-test3."
+ i + ".gz"));
}
assertTrue(Compare.compare(filenames[3], "witness/rolling/tbr-test3.3"));
}
/**
* Without compression, activeFileName set, with stop/restart
*/
public void test4() throws Exception {
String datePattern = "yyyy-MM-dd_HH_mm_ss";
PatternLayout layout1 = new PatternLayout("%c{1} - %m%n");
RollingFileAppender rfa1 = new RollingFileAppender();
rfa1.setLayout(layout1);
TimeBasedRollingPolicy tbrp1 = new TimeBasedRollingPolicy();
tbrp1.setActiveFileName("output/test4.log");
tbrp1.setFileNamePattern("output/test4-%d{" + datePattern + "}");
tbrp1.activateOptions();
rfa1.setRollingPolicy(tbrp1);
rfa1.activateOptions();
logger.addAppender(rfa1);
SimpleDateFormat sdf = new SimpleDateFormat(datePattern);
String[] filenames = new String[4];
Calendar cal = Calendar.getInstance();
for (int i = 0; i < 3; i++) {
filenames[i] = "output/test4-" + sdf.format(cal.getTime());
cal.add(Calendar.SECOND, 1);
}
filenames[3] = "output/test4.log";
System.out.println("Waiting until next second and 100 millis.");
delayUntilNextSecond(100);
System.out.println("Done waiting.");
for (int i = 0; i <= 2; i++) {
logger.debug("Hello---" + i);
Thread.sleep(500);
}
logger.removeAppender(rfa1);
rfa1.close();
PatternLayout layout2 = new PatternLayout("%c{1} - %m%n");
RollingFileAppender rfa2 = new RollingFileAppender();
rfa2.setLayout(layout2);
TimeBasedRollingPolicy tbrp2 = new TimeBasedRollingPolicy();
tbrp2.setFileNamePattern("output/test4-%d{" + datePattern + "}");
tbrp2.setActiveFileName("output/test4.log");
tbrp2.activateOptions();
rfa2.setRollingPolicy(tbrp2);
rfa2.activateOptions();
logger.addAppender(rfa2);
for (int i = 3; i <= 4; i++) {
logger.debug("Hello---" + i);
Thread.sleep(500);
}
for (int i = 0; i < 4; i++) {
assertTrue(Compare.compare(filenames[i], "witness/rolling/tbr-test4." +
i));
}
}
/**
* No compression, activeFileName set, without stop/restart
*/
public void test5() throws Exception {
PatternLayout layout = new PatternLayout("%c{1} - %m%n");
RollingFileAppender rfa = new RollingFileAppender();
rfa.setLayout(layout);
String datePattern = "yyyy-MM-dd_HH_mm_ss";
TimeBasedRollingPolicy tbrp = new TimeBasedRollingPolicy();
tbrp.setFileNamePattern("output/test5-%d{" + datePattern + "}");
tbrp.setActiveFileName("output/test5.log");
tbrp.activateOptions();
rfa.setRollingPolicy(tbrp);
rfa.activateOptions();
logger.addAppender(rfa);
SimpleDateFormat sdf = new SimpleDateFormat(datePattern);
String[] filenames = new String[4];
Calendar cal = Calendar.getInstance();
for (int i = 0; i < 3; i++) {
filenames[i] = "output/test5-" + sdf.format(cal.getTime());
cal.add(Calendar.SECOND, 1);
}
filenames[3] = "output/test5.log";
System.out.println("Waiting until next second and 100 millis.");
delayUntilNextSecond(100);
System.out.println("Done waiting.");
for (int i = 0; i < 5; i++) {
logger.debug("Hello---" + i);
Thread.sleep(500);
}
for (int i = 0; i < 4; i++) {
assertTrue(Compare.compare(filenames[i], "witness/rolling/tbr-test5." +
i));
}
}
/**
* With compression, activeFileName set, no stop/restart,
*/
public void test6() throws Exception {
PatternLayout layout = new PatternLayout("%c{1} - %m%n");
RollingFileAppender rfa = new RollingFileAppender();
rfa.setLayout(layout);
String datePattern = "yyyy-MM-dd_HH_mm_ss";
TimeBasedRollingPolicy tbrp = new TimeBasedRollingPolicy();
tbrp.setFileNamePattern("output/test6-%d{" + datePattern + "}.gz");
tbrp.setActiveFileName("output/test6.log");
tbrp.activateOptions();
rfa.setRollingPolicy(tbrp);
rfa.activateOptions();
logger.addAppender(rfa);
SimpleDateFormat sdf = new SimpleDateFormat(datePattern);
String[] filenames = new String[4];
Calendar cal = Calendar.getInstance();
for (int i = 0; i < 3; i++) {
filenames[i] = "output/test6-" + sdf.format(cal.getTime()) + ".gz";
cal.add(Calendar.SECOND, 1);
}
filenames[3] = "output/test6.log";
System.out.println("Waiting until next second and 100 millis.");
delayUntilNextSecond(100);
System.out.println("Done waiting.");
for (int i = 0; i < 5; i++) {
logger.debug("Hello---" + i);
Thread.sleep(500);
}
for (int i = 0; i < 4; i++) {
//System.out.println(i + " expected filename [" + filenames[i] + "].");
}
for (int i = 0; i < 3; i++) {
assertTrue(Compare.gzCompare(filenames[i], "witness/rolling/tbr-test6."
+ i + ".gz"));
}
assertTrue(Compare.compare(filenames[3], "witness/rolling/tbr-test6.3"));
}
public void testWithJoran1() throws Exception {
JoranConfigurator jc = new JoranConfigurator();
jc.doConfigure("./input/rolling/time1.xml",
LogManager.getLoggerRepository());
jc.dumpErrors();
String datePattern = "yyyy-MM-dd_HH_mm_ss";
SimpleDateFormat sdf = new SimpleDateFormat(datePattern);
String[] filenames = new String[4];
Calendar cal = Calendar.getInstance();
for (int i = 0; i < 4; i++) {
filenames[i] = "output/test1-" + sdf.format(cal.getTime());
cal.add(Calendar.SECOND, 1);
}
System.out.println("Waiting until next second and 100 millis.");
delayUntilNextSecond(100);
System.out.println("Done waiting.");
for (int i = 0; i < 5; i++) {
logger.debug("Hello---" + i);
Thread.sleep(500);
}
for (int i = 0; i < 4; i++) {
//System.out.println(i + " expected filename [" + filenames[i] + "].");
}
for (int i = 0; i < 4; i++) {
assertTrue(Compare.compare(filenames[i], "witness/rolling/tbr-test1." +
i));
}
}
public void XXXtestWithJoran10() throws Exception {
JoranConfigurator jc = new JoranConfigurator();
jc.doConfigure("./input/rolling/time2.xml",
LogManager.getLoggerRepository());
jc.dumpErrors();
String datePattern = "yyyy-MM-dd";
SimpleDateFormat sdf = new SimpleDateFormat(datePattern);
String[] filenames = new String[0];
Calendar cal = Calendar.getInstance();
filenames[0] = "output/test1-" + sdf.format(cal.getTime());
for (int i = 0; i < 5; i++) {
logger.debug("Hello---" + i);
Thread.sleep(500);
}
for (int i = 0; i < 1; i++) {
assertTrue(Compare.compare(filenames[i], "witness/rolling/tbr-test10."
+ i));
}
}
#endif
void delayUntilNextSecond(int millis) {
apr_time_t now = apr_time_now();
apr_time_t next = ((now / APR_USEC_PER_SEC) + 1) * APR_USEC_PER_SEC
+ millis * 1000L;
apr_sleep(next - now);
}
#if 0
void delayUntilNextMinute(int seconds) {
long now = System.currentTimeMillis();
Calendar cal = Calendar.getInstance();
cal.setTime(new Date(now));
cal.set(Calendar.SECOND, seconds);
cal.add(Calendar.MINUTE, 1);
long next = cal.getTime().getTime();
try {
Thread.sleep(next - now);
} catch (Exception e) {
}
}
public static Test XXXsuite() {
TestSuite suite = new TestSuite();
// suite.addTest(new TimeBasedRollingTest("test1"));
// suite.addTest(new TimeBasedRollingTest("test2"));
// suite.addTest(new TimeBasedRollingTest("test3"));
// suite.addTest(new TimeBasedRollingTest("test4"));
//
// suite.addTest(new TimeBasedRollingTest("test5"));
// suite.addTest(new TimeBasedRollingTest("test6"));
// suite.addTest(new TimeBasedRollingTest("testWithJoran1"));
suite.addTest(new TimeBasedRollingTest("testWithJoran10"));
return suite;
}
#endif
};
//LoggerPtr
TimeBasedRollingTest::logger("org.apache.log4j.rolling.TimeBasedRollingTest");
#endif