carnold 2005/05/24 22:33:16
Modified: src/java/org/apache/log4j/rolling
FilterBasedTriggeringPolicy.java
FixedWindowRollingPolicy.java
RollingFileAppender.java RollingPolicy.java
RollingPolicyBase.java TimeBasedRollingPolicy.java
src/java/org/apache/log4j/rolling/helper Action.java
CompositeAction.java FileRenameAction.java
GZCompressAction.java ZipCompressAction.java
tests/src/java/org/apache/log4j/rolling
SizeBasedRollingTest.java
tests/src/java/org/apache/log4j/rolling/helper
FileNamePatternTestCase.java
Added: src/java/org/apache/log4j/rolling RolloverDescription.java
RolloverDescriptionImpl.java
src/java/org/apache/log4j/rolling/helper ActionBase.java
Log:
Bug 34979: RFA - reworked interfaces
Revision Changes Path
1.4 +1 -1
logging-log4j/src/java/org/apache/log4j/rolling/FilterBasedTriggeringPolicy.java
Index: FilterBasedTriggeringPolicy.java
===================================================================
RCS file:
/home/cvs/logging-log4j/src/java/org/apache/log4j/rolling/FilterBasedTriggeringPolicy.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- FilterBasedTriggeringPolicy.java 23 May 2005 23:51:01 -0000 1.3
+++ FilterBasedTriggeringPolicy.java 25 May 2005 05:33:15 -0000 1.4
@@ -82,7 +82,7 @@
* Add a filter to end of the filter list.
* @param newFilter filter to add to end of list.
*/
- public void addFilter(Filter newFilter) {
+ public void addFilter(final Filter newFilter) {
if (headFilter == null) {
headFilter = newFilter;
tailFilter = newFilter;
1.11 +36 -31
logging-log4j/src/java/org/apache/log4j/rolling/FixedWindowRollingPolicy.java
Index: FixedWindowRollingPolicy.java
===================================================================
RCS file:
/home/cvs/logging-log4j/src/java/org/apache/log4j/rolling/FixedWindowRollingPolicy.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- FixedWindowRollingPolicy.java 23 May 2005 23:51:01 -0000 1.10
+++ FixedWindowRollingPolicy.java 25 May 2005 05:33:15 -0000 1.11
@@ -18,6 +18,7 @@
import org.apache.log4j.pattern.IntegerPatternConverter;
import org.apache.log4j.pattern.PatternConverter;
+import org.apache.log4j.rolling.helper.Action;
import org.apache.log4j.rolling.helper.FileRenameAction;
import org.apache.log4j.rolling.helper.GZCompressAction;
import org.apache.log4j.rolling.helper.ZipCompressAction;
@@ -25,8 +26,6 @@
import java.io.File;
import java.io.IOException;
-import java.util.List;
-
/**
* When rolling over, <code>FixedWindowRollingPolicy</code> renames files
@@ -151,9 +150,20 @@
/**
* [EMAIL PROTECTED]
*/
- public boolean rollover(
- final StringBuffer activeFile, List synchronousActions,
- List asynchronousActions) throws IOException {
+ public RolloverDescription initialize(
+ final String file, final boolean append) {
+ if (activeFileName != null) {
+ return new RolloverDescriptionImpl(activeFileName, append, null, null);
+ }
+
+ return null;
+ }
+
+ /**
+ * [EMAIL PROTECTED]
+ */
+ public RolloverDescription rollover(final String currentFileName)
+ throws IOException {
if (maxIndex >= 0) {
// Delete the oldest file, to keep Windows happy.
StringBuffer buf = new StringBuffer();
@@ -225,39 +235,34 @@
higherFileName = lowerFileName;
}
- activeFile.setLength(0);
- activeFile.append(activeFileName);
-
File currentFile = new File(activeFileName);
- if (currentFile.exists()) {
- //
- // add renaming of active file as something to be done
- // after closing active file
- //
- synchronousActions.add(
- new FileRenameAction(
- new File(activeFileName), new File(higherBaseName), false));
-
- if (suffixLength == 3) {
- asynchronousActions.add(
- new GZCompressAction(
- new File(higherBaseName), new File(higherFileName), true,
- getLogger()));
- }
+ if (!currentFile.exists()) {
+ return new RolloverDescriptionImpl(activeFileName, false, null,
null);
+ }
- if (suffixLength == 4) {
- asynchronousActions.add(
- new ZipCompressAction(
- new File(higherBaseName), new File(higherFileName), true,
- getLogger()));
- }
+ FileRenameAction renameAction =
+ new FileRenameAction(
+ new File(activeFileName), new File(higherBaseName), false);
+ Action compressAction = null;
+
+ if (suffixLength == 3) {
+ compressAction =
+ new GZCompressAction(
+ new File(higherBaseName), new File(higherFileName), true,
+ getLogger());
+ } else if (suffixLength == 4) {
+ compressAction =
+ new ZipCompressAction(
+ new File(higherBaseName), new File(higherFileName), true,
+ getLogger());
}
- return true;
+ return new RolloverDescriptionImpl(
+ activeFileName, false, renameAction, compressAction);
}
- return false;
+ return null;
}
/**
1.27 +112 -120
logging-log4j/src/java/org/apache/log4j/rolling/RollingFileAppender.java
Index: RollingFileAppender.java
===================================================================
RCS file:
/home/cvs/logging-log4j/src/java/org/apache/log4j/rolling/RollingFileAppender.java,v
retrieving revision 1.26
retrieving revision 1.27
diff -u -r1.26 -r1.27
--- RollingFileAppender.java 23 May 2005 23:51:01 -0000 1.26
+++ RollingFileAppender.java 25 May 2005 05:33:15 -0000 1.27
@@ -18,15 +18,10 @@
import org.apache.log4j.FileAppender;
import org.apache.log4j.rolling.helper.Action;
-import org.apache.log4j.rolling.helper.CompositeAction;
import org.apache.log4j.spi.LoggingEvent;
import java.io.*;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-
/**
* <code>RollingFileAppender</code> extends [EMAIL PROTECTED] FileAppender}
to backup the log files
@@ -90,9 +85,9 @@
private long fileLength = 0;
/**
- * Thread for any asynchronous actions from last rollover.
+ * Asynchronous action (like compression) from previous rollover.
*/
- private Thread rollingThread = null;
+ private Action lastRolloverAsyncAction = null;
/**
* Construct a new instance.
@@ -132,21 +127,28 @@
triggeringPolicy.activateOptions();
rollingPolicy.activateOptions();
- StringBuffer activeFileName = new StringBuffer();
- List synchronousActions = new ArrayList();
- List asynchronousActions = new ArrayList();
-
try {
- if (
- rollingPolicy.rollover(
- activeFileName, synchronousActions, asynchronousActions)) {
- performActions(synchronousActions, asynchronousActions);
- }
+ RolloverDescription rollover =
+ rollingPolicy.initialize(getFile(), getAppend());
- String afn = activeFileName.toString();
- setFile(afn);
+ if (rollover != null) {
+ Action syncAction = rollover.getSynchronous();
- File activeFile = new File(afn);
+ if (syncAction != null) {
+ syncAction.execute();
+ }
+
+ setFile(rollover.getActiveFileName());
+ setAppend(rollover.getAppend());
+ lastRolloverAsyncAction = rollover.getAsynchronous();
+
+ if (lastRolloverAsyncAction != null) {
+ Thread runner = new Thread(lastRolloverAsyncAction);
+ runner.start();
+ }
+ }
+
+ File activeFile = new File(getFile());
if (getAppend()) {
fileLength = activeFile.length();
@@ -162,47 +164,12 @@
if (ioException != null) {
getLogger().warn(
- "IOException while preparing while initializing RollingFileAppender
named '"
+ "IOException while initializing RollingFileAppender named '"
+ getName() + "'", ioException);
}
}
/**
- * Perform any actions specified by triggering policy.
- * @param synchronousActions list of Action instances to be performed
after active file close.
- * @param asynchronousActions list of Action instances to be performed
asynchronously after file close
- * and synchronous actions.
- * @return true if all synchronous actions were successful.
- * @throws IOException if IO error during synchronous actions.
- */
- private boolean performActions(
- final List synchronousActions, final List asynchronousActions)
- throws IOException {
- Iterator syncIterator = synchronousActions.iterator();
-
- while (syncIterator.hasNext()) {
- if (!((Action) syncIterator.next()).execute()) {
- return false;
- }
- }
-
- if (asynchronousActions.size() > 0) {
- Runnable action = null;
-
- if (asynchronousActions.size() > 1) {
- action = new CompositeAction(asynchronousActions, false,
getLogger());
- } else {
- action = (Runnable) asynchronousActions.get(0);
- }
-
- rollingThread = new Thread(action);
- rollingThread.start();
- }
-
- return true;
- }
-
- /**
Implements the usual roll over behaviour.
<p>If <code>MaxBackupIndex</code> is positive, then files
@@ -215,86 +182,114 @@
<p>If <code>MaxBackupIndex</code> is equal to zero, then the
<code>File</code> is truncated with no backup files created.
+ * @return true if rollover performed.
*/
- public void rollover() {
+ public boolean rollover() {
+ //
+ // can't roll without a policy
+ //
if (rollingPolicy != null) {
Exception exception = null;
synchronized (this) {
- try {
+ //
+ // if a previous async task is still running
+ //}
+ if (lastRolloverAsyncAction != null) {
//
- // if we have some in-process compression, etc
- // from the previous rollover, wait till they are finished.
+ // block until complete
//
- if (rollingThread != null) {
- rollingThread.join();
- rollingThread = null;
- }
+ lastRolloverAsyncAction.close();
+
+ //
+ // or don't block and return to rollover later
+ //
+ //if (!lastRolloverAsyncAction.isComplete()) return false;
+ }
+
+ try {
+ RolloverDescription rollover = rollingPolicy.rollover(getFile());
- StringBuffer activeFileName = new StringBuffer(super.getFile());
- List synchronousActions = new ArrayList();
- List asynchronousActions = new ArrayList();
-
- try {
- boolean doRollover =
- rollingPolicy.rollover(
- activeFileName, synchronousActions, asynchronousActions);
-
- if (doRollover) {
- String oldFileName = getFile();
- String newFileName = activeFileName.toString();
-
- //
- // if the file names are the same then we
- // have to close, do actions, then reopen
- if (newFileName.equals(oldFileName)) {
- closeWriter();
+ if (rollover != null) {
+ if (rollover.getActiveFileName().equals(getFile())) {
+ closeWriter();
+
+ boolean success = true;
+
+ if (rollover.getSynchronous() != null) {
+ success = false;
try {
- if (!performActions(synchronousActions,
asynchronousActions)) {
- throw new IOException(
- "Unable to complete action after active file close.");
- }
- } catch (IOException ex) {
- setFile(oldFileName, true, bufferedIO, bufferSize);
- throw ex;
+ success = rollover.getSynchronous().execute();
+ } catch (Exception ex) {
+ exception = ex;
}
+ }
- fileLength = 0;
- setFile(newFileName, false, bufferedIO, bufferSize);
+ if (success) {
+ if (rollover.getAppend()) {
+ fileLength = new
File(rollover.getActiveFileName()).length();
+ } else {
+ fileLength = 0;
+ }
+
+ if (rollover.getAsynchronous() != null) {
+ lastRolloverAsyncAction = rollover.getAsynchronous();
+ new Thread(lastRolloverAsyncAction).start();
+ }
+
+ setFile(
+ rollover.getActiveFileName(), rollover.getAppend(),
+ bufferedIO, bufferSize);
} else {
- //
- // if not the same, we can try opening new file before
- // closing old file
- if (bufferedIO) {
- setImmediateFlush(false);
+ setFile(
+ rollover.getActiveFileName(), true, bufferedIO,
bufferSize);
+
+ if (exception == null) {
+ getLogger().warn("Failure in post-close rollover action");
+ } else {
+ getLogger().warn(
+ "Exception in post-close rollover action", exception);
}
+ }
+ } else {
+ Writer newWriter =
+ createWriter(
+ new FileOutputStream(
+ rollover.getActiveFileName(), rollover.getAppend()));
+ closeWriter();
+ setFile(rollover.getActiveFileName());
+ this.writer = newWriter;
+
+ boolean success = true;
- Writer newWriter =
- createWriter(new FileOutputStream(newFileName, false));
- closeWriter();
+ if (rollover.getSynchronous() != null) {
+ success = false;
try {
- performActions(synchronousActions, asynchronousActions);
- fileLength = 0;
+ success = rollover.getSynchronous().execute();
+ } catch (Exception ex) {
+ exception = ex;
+ }
+ }
- if (bufferedIO) {
- this.writer = new BufferedWriter(newWriter, bufferSize);
- } else {
- this.writer = newWriter;
- }
- } catch (IOException ex) {
- setFile(oldFileName, true, bufferedIO, bufferSize);
- throw ex;
+ if (success) {
+ if (rollover.getAppend()) {
+ fileLength = new
File(rollover.getActiveFileName()).length();
+ } else {
+ fileLength = 0;
}
- writeHeader();
+ if (rollover.getAsynchronous() != null) {
+ lastRolloverAsyncAction = rollover.getAsynchronous();
+ new Thread(lastRolloverAsyncAction).start();
+ }
}
+
+ writeHeader();
}
- } catch (IOException ex) {
- exception = ex;
}
- } catch (InterruptedException ex) {
+ } catch (IOException ex) {
exception = ex;
}
}
@@ -304,6 +299,8 @@
"Exception during rollover, rollover deferred.", exception);
}
}
+
+ return false;
}
/**
@@ -357,15 +354,10 @@
* Close appender. Waits for any asynchronous file compression actions to
be completed.
*/
public void close() {
- if (rollingThread != null) {
- try {
- rollingThread.join();
- } catch (InterruptedException ex) {
- getLogger().info(
- "Interrupted while waiting for completion of rollover actions.",
ex);
+ synchronized (this) {
+ if (lastRolloverAsyncAction != null) {
+ lastRolloverAsyncAction.close();
}
-
- rollingThread = null;
}
super.close();
1.12 +19 -18
logging-log4j/src/java/org/apache/log4j/rolling/RollingPolicy.java
Index: RollingPolicy.java
===================================================================
RCS file:
/home/cvs/logging-log4j/src/java/org/apache/log4j/rolling/RollingPolicy.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- RollingPolicy.java 23 May 2005 23:51:01 -0000 1.11
+++ RollingPolicy.java 25 May 2005 05:33:15 -0000 1.12
@@ -20,8 +20,6 @@
import java.io.IOException;
-import java.util.List;
-
/**
* A <code>RollingPolicy</code> specifies the actions taken
@@ -33,26 +31,29 @@
* */
public interface RollingPolicy extends OptionHandler {
/**
+ * Initialize the policy and return any initial actions for rolling file
appender..
+ *
+ * @param file current value of RollingFileAppender.getFile().
+ * @param append current value of RollingFileAppender.getAppend().
+ * @return Description of the initialization, may be null to indicate
+ * no initialization needed.
+ * @throws IOException on failure.
+ */
+ public RolloverDescription initialize(
+ final String file, final boolean append) throws IOException;
+
+ /**
* Prepare for a rollover. This method is called prior to
- * closing the active log file and performs any necessary
- * preliminary actions. The rolling file appender will then
- * close the active log file, perform the synchronous actions
- * and dispatch the asynchronous files before returning
- * control to its caller.
+ * closing the active log file, performs any necessary
+ * preliminary actions and describes actions needed
+ * after close of current log file.
*
- * @param activeFile buffer containing name of the active log file on
entry,
- * and name of future active file on exit.
- * @param synchronousActions list to which instances of Runnable
- * are appended for actions to be performed after closing the active file.
- * @param asynchronousActions list to which instances of Runnable
- * are appended for actions to be performed asynchronously
- * after closing the active file and executing the synchronous actions
- * @return true if rollover should proceed. If false rollover will
- * silently be skipped.
+ * @param activeFile file name for current active log file.
+ * @return Description of pending rollover, may be null to indicate no
rollover
+ * at this time.
* @throws IOException on failure to prepare for rollover. Rollover
* will be suppressed if an exception is thrown.
*/
- public boolean rollover(
- StringBuffer activeFile, List synchronousActions, List
asynchronousActions)
+ public RolloverDescription rollover(final String activeFile)
throws IOException;
}
1.6 +3 -0
logging-log4j/src/java/org/apache/log4j/rolling/RollingPolicyBase.java
Index: RollingPolicyBase.java
===================================================================
RCS file:
/home/cvs/logging-log4j/src/java/org/apache/log4j/rolling/RollingPolicyBase.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- RollingPolicyBase.java 23 May 2005 23:51:01 -0000 1.5
+++ RollingPolicyBase.java 25 May 2005 05:33:15 -0000 1.6
@@ -54,6 +54,7 @@
/**
* Active file name may be null.
+ * @deprecated duplicates FileAppender.file and should be removed.
*/
protected String activeFileName;
@@ -80,6 +81,7 @@
/**
* ActiveFileName can be left unset, i.e. as null.
+ * @deprecated duplicates FileAppender.file and should be removed
* @see #getActiveFileName
*/
public void setActiveFileName(String afn) {
@@ -88,6 +90,7 @@
/**
* Return the value of the <b>ActiveFile</b> option.
+ * @deprecated duplicates FileAppender.file and should be removed
* @return active file name.
*/
public String getActiveFileName() {
1.23 +55 -50
logging-log4j/src/java/org/apache/log4j/rolling/TimeBasedRollingPolicy.java
Index: TimeBasedRollingPolicy.java
===================================================================
RCS file:
/home/cvs/logging-log4j/src/java/org/apache/log4j/rolling/TimeBasedRollingPolicy.java,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -r1.22 -r1.23
--- TimeBasedRollingPolicy.java 23 May 2005 23:51:01 -0000 1.22
+++ TimeBasedRollingPolicy.java 25 May 2005 05:33:15 -0000 1.23
@@ -25,7 +25,6 @@
import java.io.File;
import java.util.Date;
-import java.util.List;
/**
@@ -217,78 +216,84 @@
/**
* [EMAIL PROTECTED]
*/
- public boolean rollover(
- final StringBuffer activeFile, final List synchronousActions,
- final List asynchronousActions) {
+ public RolloverDescription initialize(
+ final String currentActiveFile, final boolean append) {
long n = System.currentTimeMillis();
nextCheck = ((n / 1000) + 1) * 1000;
StringBuffer buf = new StringBuffer();
formatFileName(new Date(n), buf);
-
- String newFileName = buf.toString();
+ lastFileName = buf.toString();
//
- // if file names haven't changed, no rollover
+ // RollingPolicyBase.activeFileName duplicates RollingFileAppender.file
+ // and should be removed.
//
- if (newFileName.equals(lastFileName)) {
- activeFile.setLength(0);
-
- if (activeFileName == null) {
- activeFile.append(
- newFileName.substring(0, newFileName.length() - suffixLength));
- } else {
- activeFile.append(activeFileName);
- }
-
- return false;
+ if (activeFileName != null) {
+ return new RolloverDescriptionImpl(activeFileName, append, null, null);
+ } else if (currentActiveFile != null) {
+ return new RolloverDescriptionImpl(
+ currentActiveFile, append, null, null);
+ } else {
+ return new RolloverDescriptionImpl(
+ lastFileName.substring(0, lastFileName.length() - suffixLength),
append,
+ null, null);
}
+ }
- File lastBaseFile =
- new File(
- lastFileName.substring(0, lastFileName.length() - suffixLength));
+ /**
+ * [EMAIL PROTECTED]
+ */
+ public RolloverDescription rollover(final String currentActiveFile) {
+ long n = System.currentTimeMillis();
+ nextCheck = ((n / 1000) + 1) * 1000;
- boolean lastFileExists = false;
+ StringBuffer buf = new StringBuffer();
+ formatFileName(new Date(n), buf);
+
+ String newFileName = buf.toString();
//
- // if no explicit active file name then
- // change active file name to new name
+ // if file names haven't changed, no rollover
//
- if (activeFileName == null) {
- lastFileExists = lastBaseFile.exists();
- activeFile.setLength(0);
- activeFile.append(newFileName);
+ if (newFileName.equals(lastFileName)) {
+ return null;
+ }
- if (suffixLength > 0) {
- activeFile.setLength(activeFile.length() - suffixLength);
- }
- } else {
- activeFile.setLength(0);
- activeFile.append(activeFileName);
+ Action renameAction = null;
+ Action compressAction = null;
+ String lastBaseName =
+ lastFileName.substring(0, lastFileName.length() - suffixLength);
+ String nextActiveFile =
+ newFileName.substring(0, newFileName.length() - suffixLength);
- File currentActiveFile = new File(activeFileName);
- lastFileExists = currentActiveFile.exists();
- synchronousActions.add(
- new FileRenameAction(currentActiveFile, lastBaseFile, true));
+ //
+ // if currentActiveFile is not lastBaseName then
+ // active file name is not following file pattern
+ // and requires a rename plus maintaining the same name
+ if (!currentActiveFile.equals(lastBaseName)) {
+ renameAction =
+ new FileRenameAction(
+ new File(currentActiveFile), new File(lastBaseName), true);
+ nextActiveFile = currentActiveFile;
}
- if ((suffixLength > 0) && lastFileExists) {
- File compressedFile = new File(lastFileName);
+ if (suffixLength == 3) {
+ compressAction =
+ new GZCompressAction(
+ new File(lastBaseName), new File(lastFileName), true, getLogger());
+ }
- if (suffixLength == 3) {
- asynchronousActions.add(
- new GZCompressAction(
- lastBaseFile, compressedFile, true, getLogger()));
- } else if (suffixLength == 4) {
- asynchronousActions.add(
- new ZipCompressAction(
- lastBaseFile, compressedFile, true, getLogger()));
- }
+ if (suffixLength == 4) {
+ compressAction =
+ new ZipCompressAction(
+ new File(lastBaseName), new File(lastFileName), true, getLogger());
}
lastFileName = newFileName;
- return true;
+ return new RolloverDescriptionImpl(
+ nextActiveFile, false, renameAction, compressAction);
}
/**
1.1
logging-log4j/src/java/org/apache/log4j/rolling/RolloverDescription.java
Index: RolloverDescription.java
===================================================================
/*
* 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.
*/
package org.apache.log4j.rolling;
import org.apache.log4j.rolling.helper.Action;
/**
* Description of actions needed to complete rollover.
*
* @author Curt Arnold
* @since 1.3
*
*/
public interface RolloverDescription {
/**
* Active log file name after rollover.
* @return active log file name after rollover.
*/
String getActiveFileName();
/**
* Specifies if active file should be opened for appending.
* @return if true, active file should be opened for appending.
*/
boolean getAppend();
/**
* Action to be completed after close of current active log file
* before returning control to caller.
*
* @return action, may be null.
*/
Action getSynchronous();
/**
* Action to be completed after close of current active log file
* and before next rollover attempt, may be executed asynchronously.
*
* @return action, may be null.
*/
Action getAsynchronous();
}
1.1
logging-log4j/src/java/org/apache/log4j/rolling/RolloverDescriptionImpl.java
Index: RolloverDescriptionImpl.java
===================================================================
/*
* 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.
*/
package org.apache.log4j.rolling;
import org.apache.log4j.rolling.helper.Action;
/**
* Description of actions needed to complete rollover.
*
* @author Curt Arnold
* @since 1.3
*
*/
public final class RolloverDescriptionImpl implements RolloverDescription {
/**
* Active log file name after rollover.
*/
private final String activeFileName;
/**
* Should active file be opened for appending.
*/
private final boolean append;
/**
* Action to be completed after close of current active log file
* before returning control to caller.
*/
private final Action synchronous;
/**
* Action to be completed after close of current active log file
* and before next rollover attempt, may be executed asynchronously.
*/
private final Action asynchronous;
/**
* Create new instance.
* @param activeFileName active log file name after rollover, may not be
null.
* @param append true if active log file after rollover should be opened
for appending.
* @param synchronous action to be completed after close of current active
log file, may be null.
* @param asynchronous action to be completed after close of current active
log file and
* before next rollover attempt.
*/
public RolloverDescriptionImpl(
final String activeFileName, final boolean append, final Action
synchronous,
final Action asynchronous) {
if (activeFileName == null) {
throw new NullPointerException("activeFileName");
}
this.append = append;
this.activeFileName = activeFileName;
this.synchronous = synchronous;
this.asynchronous = asynchronous;
}
/**
* Active log file name after rollover.
* @return active log file name after rollover.
*/
public String getActiveFileName() {
return activeFileName;
}
/**
* [EMAIL PROTECTED]
*/
public boolean getAppend() {
return append;
}
/**
* Action to be completed after close of current active log file
* before returning control to caller.
*
* @return action, may be null.
*/
public Action getSynchronous() {
return synchronous;
}
/**
* Action to be completed after close of current active log file
* and before next rollover attempt, may be executed asynchronously.
*
* @return action, may be null.
*/
public Action getAsynchronous() {
return asynchronous;
}
}
1.2 +11 -0
logging-log4j/src/java/org/apache/log4j/rolling/helper/Action.java
Index: Action.java
===================================================================
RCS file:
/home/cvs/logging-log4j/src/java/org/apache/log4j/rolling/helper/Action.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- Action.java 23 May 2005 23:51:01 -0000 1.1
+++ Action.java 25 May 2005 05:33:15 -0000 1.2
@@ -36,4 +36,15 @@
* to be aborted if possible.
*/
boolean execute() throws IOException;
+
+ /**
+ * Cancels the action if not already initialized or waits till
completion.
+ */
+ void close();
+
+ /**
+ * Determines if action has been completed.
+ * @return true if action is complete.
+ */
+ boolean isComplete();
}
1.2 +1 -1
logging-log4j/src/java/org/apache/log4j/rolling/helper/CompositeAction.java
Index: CompositeAction.java
===================================================================
RCS file:
/home/cvs/logging-log4j/src/java/org/apache/log4j/rolling/helper/CompositeAction.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- CompositeAction.java 23 May 2005 23:51:01 -0000 1.1
+++ CompositeAction.java 25 May 2005 05:33:15 -0000 1.2
@@ -29,7 +29,7 @@
* @since 1.3
*
*/
-public class CompositeAction implements Action {
+public class CompositeAction extends ActionBase {
/**
* Actions to perform.
*/
1.3 +1 -8
logging-log4j/src/java/org/apache/log4j/rolling/helper/FileRenameAction.java
Index: FileRenameAction.java
===================================================================
RCS file:
/home/cvs/logging-log4j/src/java/org/apache/log4j/rolling/helper/FileRenameAction.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- FileRenameAction.java 24 May 2005 06:07:45 -0000 1.2
+++ FileRenameAction.java 25 May 2005 05:33:15 -0000 1.3
@@ -25,7 +25,7 @@
* @author Curt Arnold
* @since 1.3
*/
-public final class FileRenameAction implements Action {
+public final class FileRenameAction extends ActionBase {
/**
* Source.
*/
@@ -79,11 +79,4 @@
return source.delete();
}
-
- /**
- * @inheritDoc
- */
- public void run() {
- execute();
- }
}
1.2 +12 -13
logging-log4j/src/java/org/apache/log4j/rolling/helper/GZCompressAction.java
Index: GZCompressAction.java
===================================================================
RCS file:
/home/cvs/logging-log4j/src/java/org/apache/log4j/rolling/helper/GZCompressAction.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- GZCompressAction.java 23 May 2005 23:51:01 -0000 1.1
+++ GZCompressAction.java 25 May 2005 05:33:15 -0000 1.2
@@ -32,7 +32,7 @@
* @author Curt Arnold
* @since 1.3
*/
-public final class GZCompressAction implements Action {
+public final class GZCompressAction extends ActionBase {
/**
* Source file.
*/
@@ -128,17 +128,16 @@
return false;
}
- /**
- * [EMAIL PROTECTED]
- */
- public void run() {
- try {
- execute();
- } catch (IOException ex) {
- if (logger != null) {
- logger.info(
- "Exception while compressing '" + source.toString() + "'.", ex);
- }
+
+ /**
+ * Capture exception.
+ *
+ * @param ex exception.
+ */
+ protected void reportException(final Exception ex) {
+ if (logger != null) {
+ logger.info("Exception during compression of '" +
source.toString() + "'.", ex);
+ }
}
- }
+
}
1.2 +10 -13
logging-log4j/src/java/org/apache/log4j/rolling/helper/ZipCompressAction.java
Index: ZipCompressAction.java
===================================================================
RCS file:
/home/cvs/logging-log4j/src/java/org/apache/log4j/rolling/helper/ZipCompressAction.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ZipCompressAction.java 23 May 2005 23:51:01 -0000 1.1
+++ ZipCompressAction.java 25 May 2005 05:33:15 -0000 1.2
@@ -33,7 +33,7 @@
* @author Curt Arnold
* @since 1.3
*/
-public final class ZipCompressAction implements Action {
+public final class ZipCompressAction extends ActionBase {
/**
* Source file.
*/
@@ -133,17 +133,14 @@
return false;
}
- /**
- * [EMAIL PROTECTED]
- */
- public void run() {
- try {
- execute();
- } catch (IOException ex) {
- if (logger != null) {
- logger.info(
- "Exception while compressing '" + source.toString() + "'.", ex);
- }
+ /**
+ * Capture exception.
+ *
+ * @param ex exception.
+ */
+ protected void reportException(final Exception ex) {
+ if (logger != null) {
+ logger.info("Exception during compression of '" +
source.toString() + "'.", ex);
+ }
}
- }
}
1.1
logging-log4j/src/java/org/apache/log4j/rolling/helper/ActionBase.java
Index: ActionBase.java
===================================================================
/*
* 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.
*/
package org.apache.log4j.rolling.helper;
import java.io.IOException;
/**
* Abstract base class for implementations of Action.
*
* @author Curt Arnold
* @since 1.3
*/
public abstract class ActionBase implements Action {
/**
* Is action complete.
*/
private boolean complete = false;
/**
* Is action interrupted.
*/
private boolean interrupted = false;
/**
* Constructor.
*/
protected ActionBase() {
}
/**
* Perform action.
*
* @return true if successful.
*/
public abstract boolean execute() throws IOException;
/**
* [EMAIL PROTECTED]
*/
public synchronized void run() {
if (!interrupted) {
try {
execute();
} catch(IOException ex) {
reportException(ex);
}
complete = true;
interrupted = true;
}
}
/**
* [EMAIL PROTECTED]
*/
public synchronized void close() {
interrupted = true;
}
/**
* Tests if the action is complete.
* @return true if action is complete.
*/
public boolean isComplete() {
return complete;
}
/**
* Capture exception.
*
* @param ex exception.
*/
protected void reportException(final Exception ex) {
}
}
1.14 +4 -1
logging-log4j/tests/src/java/org/apache/log4j/rolling/SizeBasedRollingTest.java
Index: SizeBasedRollingTest.java
===================================================================
RCS file:
/home/cvs/logging-log4j/tests/src/java/org/apache/log4j/rolling/SizeBasedRollingTest.java,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- SizeBasedRollingTest.java 12 May 2005 03:55:46 -0000 1.13
+++ SizeBasedRollingTest.java 25 May 2005 05:33:15 -0000 1.14
@@ -64,6 +64,7 @@
// This makes the regression test system independent.
PatternLayout layout = new PatternLayout("%m\n");
RollingFileAppender rfa = new RollingFileAppender();
+ rfa.setAppend(false);
rfa.setLayout(layout);
FixedWindowRollingPolicy fwrp = new FixedWindowRollingPolicy();
@@ -85,7 +86,8 @@
public void test2() throws Exception {
PatternLayout layout = new PatternLayout("%m\n");
RollingFileAppender rfa = new RollingFileAppender();
- rfa.setName("ROLLING");
+ rfa.setName("ROLLING");
+ rfa.setAppend(false);
rfa.setLayout(layout);
FixedWindowRollingPolicy swrp = new FixedWindowRollingPolicy();
@@ -131,6 +133,7 @@
public void test3() throws Exception {
PatternLayout layout = new PatternLayout("%m\n");
RollingFileAppender rfa = new RollingFileAppender();
+ rfa.setAppend(false);
rfa.setLayout(layout);
FixedWindowRollingPolicy fwrp = new FixedWindowRollingPolicy();
1.5 +6 -5
logging-log4j/tests/src/java/org/apache/log4j/rolling/helper/FileNamePatternTestCase.java
Index: FileNamePatternTestCase.java
===================================================================
RCS file:
/home/cvs/logging-log4j/tests/src/java/org/apache/log4j/rolling/helper/FileNamePatternTestCase.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- FileNamePatternTestCase.java 23 May 2005 23:51:01 -0000 1.4
+++ FileNamePatternTestCase.java 25 May 2005 05:33:15 -0000 1.5
@@ -16,12 +16,12 @@
package org.apache.log4j.rolling.helper;
import org.apache.log4j.rolling.RollingPolicyBase;
+import org.apache.log4j.rolling.RolloverDescription;
import junit.framework.TestCase;
import java.util.Calendar;
import org.apache.log4j.ULogger;
-import java.util.List;
/**
@@ -51,10 +51,11 @@
public String getActiveFileName() {
return null;
}
- public boolean rollover(final StringBuffer activeName,
- final List synchronousActions,
- final List asynchronousActions) {
- return false;
+ public RolloverDescription initialize(final String activeName, final
boolean append) {
+ return null;
+ }
+ public RolloverDescription rollover(final String activeName) {
+ return null;
}
public ULogger getLogger() {
return null;
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]