[logback-dev] [GIT] Logback: the generic, reliable, fast and flexible logging framework. branch, master, updated. v0.9.20-14-g729c58c
added by portage for gitosis-gentoo
git-noreply at pixie.qos.ch
Sat May 8 18:49:05 CEST 2010
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "Logback: the generic, reliable, fast and flexible logging framework.".
The branch, master has been updated
via 729c58c5a6be3022f463a3f66e15eb70939eacdf (commit)
via cbd336b71ef1842babf7ccdcf59e63861beef0ab (commit)
from 5e93537ed06b334bd3f57f577f0545d598caae13 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
http://git.qos.ch/gitweb/?p=logback.git;a=commit;h=729c58c5a6be3022f463a3f66e15eb70939eacdf
http://github.com/ceki/logback/commit/729c58c5a6be3022f463a3f66e15eb70939eacdf
commit 729c58c5a6be3022f463a3f66e15eb70939eacdf
Author: Ceki Gulcu <ceki at qos.ch>
Date: Sat May 8 18:45:21 2010 +0200
- fixed http://jira.qos.ch/browse/LBCORE-151
- removed previoulsy deprecated getFirstFilter() method in
FilterAttachable interface
diff --git a/logback-access/src/main/java/ch/qos/logback/access/jetty/RequestLogImpl.java b/logback-access/src/main/java/ch/qos/logback/access/jetty/RequestLogImpl.java
index b194050..d4a624a 100644
--- a/logback-access/src/main/java/ch/qos/logback/access/jetty/RequestLogImpl.java
+++ b/logback-access/src/main/java/ch/qos/logback/access/jetty/RequestLogImpl.java
@@ -248,7 +248,4 @@ public class RequestLogImpl extends ContextBase implements RequestLog,
return fai.getFilterChainDecision(event);
}
- public Filter getFirstFilter() {
- return fai.getFirstFilter();
- }
}
diff --git a/logback-access/src/main/java/ch/qos/logback/access/jetty/v7/RequestLogImpl.java b/logback-access/src/main/java/ch/qos/logback/access/jetty/v7/RequestLogImpl.java
index 35bd8ce..95742fa 100644
--- a/logback-access/src/main/java/ch/qos/logback/access/jetty/v7/RequestLogImpl.java
+++ b/logback-access/src/main/java/ch/qos/logback/access/jetty/v7/RequestLogImpl.java
@@ -249,8 +249,4 @@ public class RequestLogImpl extends ContextBase implements RequestLog,
public FilterReply getFilterChainDecision(AccessEvent event) {
return fai.getFilterChainDecision(event);
}
-
- public Filter getFirstFilter() {
- return fai.getFirstFilter();
- }
}
\ No newline at end of file
diff --git a/logback-access/src/main/java/ch/qos/logback/access/spi/AccessContext.java b/logback-access/src/main/java/ch/qos/logback/access/spi/AccessContext.java
index 2c55c6e..a8a3069 100644
--- a/logback-access/src/main/java/ch/qos/logback/access/spi/AccessContext.java
+++ b/logback-access/src/main/java/ch/qos/logback/access/spi/AccessContext.java
@@ -84,8 +84,4 @@ public class AccessContext extends ContextBase implements
public FilterReply getFilterChainDecision(AccessEvent event) {
return fai.getFilterChainDecision(event);
}
-
- public Filter<AccessEvent> getFirstFilter() {
- return fai.getFirstFilter();
- }
}
diff --git a/logback-access/src/main/java/ch/qos/logback/access/tomcat/LogbackValve.java b/logback-access/src/main/java/ch/qos/logback/access/tomcat/LogbackValve.java
index d19ddbb..dc84dec 100644
--- a/logback-access/src/main/java/ch/qos/logback/access/tomcat/LogbackValve.java
+++ b/logback-access/src/main/java/ch/qos/logback/access/tomcat/LogbackValve.java
@@ -241,10 +241,6 @@ public class LogbackValve extends ValveBase implements Lifecycle, Context,
fai.addFilter(newFilter);
}
- public Filter getFirstFilter() {
- return fai.getFirstFilter();
- }
-
public void clearAllFilters() {
fai.clearAllFilters();
}
diff --git a/logback-classic/src/test/java/ch/qos/logback/classic/rolling/TimeBasedRollingWithConfigFileTest.java b/logback-classic/src/test/java/ch/qos/logback/classic/rolling/TimeBasedRollingWithConfigFileTest.java
index f25d981..7c6ec36 100644
--- a/logback-classic/src/test/java/ch/qos/logback/classic/rolling/TimeBasedRollingWithConfigFileTest.java
+++ b/logback-classic/src/test/java/ch/qos/logback/classic/rolling/TimeBasedRollingWithConfigFileTest.java
@@ -34,7 +34,7 @@ import ch.qos.logback.core.rolling.TimeBasedRollingPolicy;
import ch.qos.logback.core.status.StatusChecker;
public class TimeBasedRollingWithConfigFileTest extends
- ScaffoldingForRollingTests {
+ ScaffoldingForRollingTests {
LoggerContext lc = new LoggerContext();
Logger logger = lc.getLogger(this.getClass());
@@ -67,7 +67,7 @@ public class TimeBasedRollingWithConfigFileTest extends
String testId = "basic";
lc.putProperty("testId", testId);
loadConfig(ClassicTestConstants.JORAN_INPUT_PREFIX + "rolling/" + testId
- + ".xml");
+ + ".xml");
StatusChecker sc = new StatusChecker(lc);
assertTrue(sc.isErrorFree());
@@ -76,18 +76,18 @@ public class TimeBasedRollingWithConfigFileTest extends
expectedFilenameList.add(randomOutputDir + "z" + testId);
RollingFileAppender<ILoggingEvent> rfa = (RollingFileAppender<ILoggingEvent>) root
- .getAppender("ROLLING");
+ .getAppender("ROLLING");
TimeBasedRollingPolicy tprp = (TimeBasedRollingPolicy<ILoggingEvent>) rfa
- .getTriggeringPolicy();
+ .getTriggeringPolicy();
TimeBasedFileNamingAndTriggeringPolicy tbnatp = tprp
- .getTimeBasedFileNamingAndTriggeringPolicy();
+ .getTimeBasedFileNamingAndTriggeringPolicy();
String prefix = "Hello---";
int runLength = 4;
for (int i = 0; i < runLength; i++) {
logger.debug(prefix + i);
- addExpectedFileNamedIfItsTime_ByDate(testId, false);
+ addExpectedFileNamedIfItsTime_ByDate(randomOutputDir, testId, false);
incCurrentTime(500);
tbnatp.setCurrentTime(currentTime);
}
@@ -108,21 +108,21 @@ public class TimeBasedRollingWithConfigFileTest extends
sizeThreshold = prefix.length() * approxWritesPerPeriod;
lc.putProperty("sizeThreshold", "" + sizeThreshold);
loadConfig(ClassicTestConstants.JORAN_INPUT_PREFIX + "rolling/" + testId
- + ".xml");
+ + ".xml");
Logger root = lc.getLogger(Logger.ROOT_LOGGER_NAME);
expectedFilenameList.add(randomOutputDir + "z" + testId);
RollingFileAppender<ILoggingEvent> rfa = (RollingFileAppender<ILoggingEvent>) root
- .getAppender("ROLLING");
+ .getAppender("ROLLING");
StatusChecker sc = new StatusChecker(lc);
assertTrue(sc.isErrorFree());
TimeBasedRollingPolicy tprp = (TimeBasedRollingPolicy<ILoggingEvent>) rfa
- .getTriggeringPolicy();
+ .getTriggeringPolicy();
TimeBasedFileNamingAndTriggeringPolicy tbnatp = tprp
- .getTimeBasedFileNamingAndTriggeringPolicy();
+ .getTimeBasedFileNamingAndTriggeringPolicy();
int timeIncrement = 1000 / approxWritesPerPeriod;
int runLength = approxWritesPerPeriod * 3;
@@ -140,19 +140,19 @@ public class TimeBasedRollingWithConfigFileTest extends
// match exactly the expected archive files. Thus, we aim for
// an approximate match
assertTrue("exitenceCount=" + eCount + ", expectedFilenameList.size="
- + expectedFilenameList.size(), eCount >= 4
- && eCount > expectedFilenameList.size() / 2);
+ + expectedFilenameList.size(), eCount >= 4
+ && eCount > expectedFilenameList.size() / 2);
}
void addExpectedFileNamedIfItsTime(String testId, String msg,
- boolean gzExtension) {
+ boolean gzExtension) {
fileSize += msg.getBytes().length;
if (passThresholdTime(nextRolloverThreshold)) {
fileIndexCounter = 0;
fileSize = 0;
addExpectedFileName(testId, getDateOfPreviousPeriodsStart(),
- fileIndexCounter, gzExtension);
+ fileIndexCounter, gzExtension);
recomputeRolloverThreshold(currentTime);
return;
}
@@ -161,17 +161,17 @@ public class TimeBasedRollingWithConfigFileTest extends
// fileIndexCounter 0 and 1
if ((fileIndexCounter < 1) && fileSize > sizeThreshold) {
addExpectedFileName(testId, getDateOfPreviousPeriodsStart(),
- ++fileIndexCounter, gzExtension);
+ ++fileIndexCounter, gzExtension);
fileSize = -1;
return;
}
}
void addExpectedFileName(String testId, Date date, int fileIndexCounter,
- boolean gzExtension) {
+ boolean gzExtension) {
String fn = randomOutputDir + testId + "-" + SDF.format(date) + "."
- + fileIndexCounter;
+ + fileIndexCounter;
System.out.println("Adding " + fn);
if (gzExtension) {
fn += ".gz";
@@ -180,11 +180,11 @@ public class TimeBasedRollingWithConfigFileTest extends
}
@Override
- protected void addExpectedFileNamedIfItsTime_ByDate(String testId,
- boolean gzExtension) {
+ protected void addExpectedFileNamedIfItsTime_ByDate(String outputDir, String testId,
+ boolean gzExtension) {
if (passThresholdTime(nextRolloverThreshold)) {
- addExpectedFileName_ByDate(testId, getDateOfPreviousPeriodsStart(),
- gzExtension);
+ addExpectedFileName_ByDate(outputDir, testId, getDateOfPreviousPeriodsStart(),
+ gzExtension);
recomputeRolloverThreshold(currentTime);
}
}
diff --git a/logback-core/src/main/java/ch/qos/logback/core/AppenderBase.java b/logback-core/src/main/java/ch/qos/logback/core/AppenderBase.java
index b6939bf..9733b34 100644
--- a/logback-core/src/main/java/ch/qos/logback/core/AppenderBase.java
+++ b/logback-core/src/main/java/ch/qos/logback/core/AppenderBase.java
@@ -122,10 +122,6 @@ abstract public class AppenderBase<E> extends ContextAwareBase implements
fai.addFilter(newFilter);
}
- public Filter getFirstFilter() {
- return fai.getFirstFilter();
- }
-
public void clearAllFilters() {
fai.clearAllFilters();
}
diff --git a/logback-core/src/main/java/ch/qos/logback/core/FileAppender.java b/logback-core/src/main/java/ch/qos/logback/core/FileAppender.java
index 1dfbb39..c26d0c6 100644
--- a/logback-core/src/main/java/ch/qos/logback/core/FileAppender.java
+++ b/logback-core/src/main/java/ch/qos/logback/core/FileAppender.java
@@ -152,7 +152,7 @@ public class FileAppender<E> extends OutputStreamAppender<E> {
public void openFile(String file_name) throws IOException {
synchronized (lock) {
File file = new File(file_name);
- if (FileUtil.mustCreateParentDirectories(file)) {
+ if (FileUtil.isParentDirectoryCreationRequired(file)) {
boolean result = FileUtil.createMissingParentDirectories(file);
if (!result) {
addError("Failed to create parent directories for ["
diff --git a/logback-core/src/main/java/ch/qos/logback/core/UnsynchronizedAppenderBase.java b/logback-core/src/main/java/ch/qos/logback/core/UnsynchronizedAppenderBase.java
index 8c9efe3..64a0d20 100644
--- a/logback-core/src/main/java/ch/qos/logback/core/UnsynchronizedAppenderBase.java
+++ b/logback-core/src/main/java/ch/qos/logback/core/UnsynchronizedAppenderBase.java
@@ -128,10 +128,6 @@ abstract public class UnsynchronizedAppenderBase<E> extends ContextAwareBase imp
fai.addFilter(newFilter);
}
- public Filter getFirstFilter() {
- return fai.getFirstFilter();
- }
-
public void clearAllFilters() {
fai.clearAllFilters();
}
diff --git a/logback-core/src/main/java/ch/qos/logback/core/rolling/TimeBasedFileNamingAndTriggeringPolicy.java b/logback-core/src/main/java/ch/qos/logback/core/rolling/TimeBasedFileNamingAndTriggeringPolicy.java
index e76b0f0..cab4c4b 100644
--- a/logback-core/src/main/java/ch/qos/logback/core/rolling/TimeBasedFileNamingAndTriggeringPolicy.java
+++ b/logback-core/src/main/java/ch/qos/logback/core/rolling/TimeBasedFileNamingAndTriggeringPolicy.java
@@ -1,84 +1,84 @@
-/**
- * Logback: the reliable, generic, fast and flexible logging framework.
- * Copyright (C) 1999-2009, QOS.ch. All rights reserved.
- *
- * This program and the accompanying materials are dual-licensed under
- * either the terms of the Eclipse Public License v1.0 as published by
- * the Eclipse Foundation
- *
- * or (per the licensee's choosing)
- *
- * under the terms of the GNU Lesser General Public License version 2.1
- * as published by the Free Software Foundation.
- */
-package ch.qos.logback.core.rolling;
-
-import ch.qos.logback.core.rolling.helper.ArchiveRemover;
-import ch.qos.logback.core.spi.ContextAware;
-
-/**
- * This interface lists the set of methods that need to be implemented by
- * triggering policies which are nested within a {@link TimeBasedRollingPolicy}.
- *
- * @author Ceki Gülcü
- *
- * @param <E>
- */
-public interface TimeBasedFileNamingAndTriggeringPolicy<E> extends
- TriggeringPolicy<E>, ContextAware {
-
- /**
- * Set the host/parent {@link TimeBasedRollingPolicy}.
- *
- * @param the
- * parent TimeBasedRollingPolicy
- */
- void setTimeBasedRollingPolicy(TimeBasedRollingPolicy<E> tbrp);
-
- /**
- * Return the file name for the elapsed periods file name.
- *
- * @return
- */
- String getElapsedPeriodsFileName();
-
- /**
- * Return the current periods file name without the compression suffix. This
- * value is equivalent to the active file name.
- *
- * @return current period's file name (without compression suffix)
- */
- String getCurrentPeriodsFileNameWithoutCompressionSuffix();
-
- /**
- * Return the archive remover appropriate for this instance.
- */
- public ArchiveRemover getArchiveRemover();
-
- /**
- * Return the current time which is usually the value returned by
- * System.currentMillis(). However, for <b>testing</b> purposed this value
- * may be different than the real time.
- *
- * @return current time value
- */
- long getCurrentTime();
-
- /**
- * Set the current time. Only unit tests should invoke this method.
- *
- * @param now
- */
- void setCurrentTime(long now);
-
- /**
- * Set some date in the current period. Only unit tests should invoke this
- * method.
- *
- * WARNING: method removed. A unit test should not set the
- * date in current period. It is the job of the FNATP to compute that.
- *
- * @param date
- */
- //void setDateInCurrentPeriod(Date date);
-}
+/**
+ * Logback: the reliable, generic, fast and flexible logging framework.
+ * Copyright (C) 1999-2009, QOS.ch. All rights reserved.
+ *
+ * This program and the accompanying materials are dual-licensed under
+ * either the terms of the Eclipse Public License v1.0 as published by
+ * the Eclipse Foundation
+ *
+ * or (per the licensee's choosing)
+ *
+ * under the terms of the GNU Lesser General Public License version 2.1
+ * as published by the Free Software Foundation.
+ */
+package ch.qos.logback.core.rolling;
+
+import ch.qos.logback.core.rolling.helper.ArchiveRemover;
+import ch.qos.logback.core.spi.ContextAware;
+
+/**
+ * This interface lists the set of methods that need to be implemented by
+ * triggering policies which are nested within a {@link TimeBasedRollingPolicy}.
+ *
+ * @author Ceki Gülcü
+ *
+ * @param <E>
+ */
+public interface TimeBasedFileNamingAndTriggeringPolicy<E> extends
+ TriggeringPolicy<E>, ContextAware {
+
+ /**
+ * Set the host/parent {@link TimeBasedRollingPolicy}.
+ *
+ * @param tbrp
+ * parent TimeBasedRollingPolicy
+ */
+ void setTimeBasedRollingPolicy(TimeBasedRollingPolicy<E> tbrp);
+
+ /**
+ * Return the file name for the elapsed periods file name.
+ *
+ * @return
+ */
+ String getElapsedPeriodsFileName();
+
+ /**
+ * Return the current periods file name without the compression suffix. This
+ * value is equivalent to the active file name.
+ *
+ * @return current period's file name (without compression suffix)
+ */
+ String getCurrentPeriodsFileNameWithoutCompressionSuffix();
+
+ /**
+ * Return the archive remover appropriate for this instance.
+ */
+ public ArchiveRemover getArchiveRemover();
+
+ /**
+ * Return the current time which is usually the value returned by
+ * System.currentMillis(). However, for <b>testing</b> purposed this value
+ * may be different than the real time.
+ *
+ * @return current time value
+ */
+ long getCurrentTime();
+
+ /**
+ * Set the current time. Only unit tests should invoke this method.
+ *
+ * @param now
+ */
+ void setCurrentTime(long now);
+
+ /**
+ * Set some date in the current period. Only unit tests should invoke this
+ * method.
+ *
+ * WARNING: method removed. A unit test should not set the
+ * date in current period. It is the job of the FNATP to compute that.
+ *
+ * @param date
+ */
+ //void setDateInCurrentPeriod(Date date);
+}
diff --git a/logback-core/src/main/java/ch/qos/logback/core/rolling/TimeBasedRollingPolicy.java b/logback-core/src/main/java/ch/qos/logback/core/rolling/TimeBasedRollingPolicy.java
index 9de332b..ec13f36 100644
--- a/logback-core/src/main/java/ch/qos/logback/core/rolling/TimeBasedRollingPolicy.java
+++ b/logback-core/src/main/java/ch/qos/logback/core/rolling/TimeBasedRollingPolicy.java
@@ -70,6 +70,7 @@ public class TimeBasedRollingPolicy<E> extends RollingPolicyBase implements
compressor = new Compressor(compressionMode);
compressor.setContext(context);
+ // wcs : without compression suffix
fileNamePatternWCS = new FileNamePattern(computeFileNameStr_WCS(
fileNamePatternStr, compressionMode), this.context);
@@ -126,7 +127,7 @@ public class TimeBasedRollingPolicy<E> extends RollingPolicyBase implements
if (compressionMode == CompressionMode.NONE) {
if (getParentsRawFileProperty() != null) {
renameUtil.rename(getParentsRawFileProperty(), elapsedPeriodsFileName);
- }
+ } // else { nothing to do if CompressionMode == NONE and parentsRawFileProperty == null }
} else {
if (getParentsRawFileProperty() == null) {
future = asyncCompress(elapsedPeriodsFileName, elapsedPeriodsFileName);
diff --git a/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/RenameUtil.java b/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/RenameUtil.java
index 81b9a33..c609cc0 100644
--- a/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/RenameUtil.java
+++ b/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/RenameUtil.java
@@ -21,40 +21,44 @@ import java.io.IOException;
import ch.qos.logback.core.rolling.RolloverFailure;
import ch.qos.logback.core.spi.ContextAwareBase;
+import ch.qos.logback.core.util.FileUtil;
/**
* Utility class to help solving problems encountered while renaming files.
- * @author Ceki Gulcu
+ *
+ * @author Ceki Gulcu
*/
public class RenameUtil extends ContextAwareBase {
-
+
/**
* A robust file renaming method which in case of failure falls back to
* renaming by copying. In case, the file to be renamed is open by another
* process, renaming by copying will succeed whereas regular renaming will
* fail. However, renaming by copying is much slower.
- *
+ *
* @param from
* @param to
* @throws RolloverFailure
*/
public void rename(String from, String to) throws RolloverFailure {
- if(from.equals(to)) {
- addWarn("From and to file are the same ["+from+"]. Skipping.");
+ if (from.equals(to)) {
+ addWarn("From and to file are the same [" + from + "]. Skipping.");
return;
}
File fromFile = new File(from);
if (fromFile.exists()) {
File toFile = new File(to);
- addInfo("Renaming file ["+fromFile+"] to ["+toFile+"]");
+ createMissingTargetDirsIfNecessary(toFile);
+
+ addInfo("Renaming file [" + fromFile + "] to [" + toFile + "]");
boolean result = fromFile.renameTo(toFile);
if (!result) {
- addWarn("Failed to rename file ["+fromFile+"] to ["+toFile+"].");
+ addWarn("Failed to rename file [" + fromFile + "] to [" + toFile + "].");
addWarn("Attempting to rename by copying.");
renameByCopying(from, to);
}
@@ -63,10 +67,10 @@ public class RenameUtil extends ContextAwareBase {
}
}
- static final int BUF_SIZE = 32*1024;
-
+ static final int BUF_SIZE = 32 * 1024;
+
public void renameByCopying(String from, String to)
- throws RolloverFailure {
+ throws RolloverFailure {
try {
FileInputStream fis = new FileInputStream(from);
FileOutputStream fos = new FileOutputStream(to);
@@ -83,14 +87,24 @@ public class RenameUtil extends ContextAwareBase {
File fromFile = new File(from);
if (!fromFile.delete()) {
- addWarn("Could not delete "+ from);
+ addWarn("Could not delete " + from);
}
} catch (IOException ioe) {
addError("Failed to rename file by copying", ioe);
throw new RolloverFailure("Failed to rename file by copying");
}
}
-
+
+ void createMissingTargetDirsIfNecessary(File toFile) throws RolloverFailure {
+ if (FileUtil.isParentDirectoryCreationRequired(toFile)) {
+ boolean result = FileUtil.createMissingParentDirectories(toFile);
+ if (!result) {
+ throw new RolloverFailure("Failed to create parent directories for ["
+ + toFile.getAbsolutePath() + "]");
+ }
+ }
+ }
+
@Override
public String toString() {
return "c.q.l.co.rolling.helper.RenameUtil";
diff --git a/logback-core/src/main/java/ch/qos/logback/core/spi/FilterAttachable.java b/logback-core/src/main/java/ch/qos/logback/core/spi/FilterAttachable.java
index 72eda36..4cc4883 100644
--- a/logback-core/src/main/java/ch/qos/logback/core/spi/FilterAttachable.java
+++ b/logback-core/src/main/java/ch/qos/logback/core/spi/FilterAttachable.java
@@ -28,14 +28,6 @@ public interface FilterAttachable<E> {
*/
public void addFilter(Filter<E> newFilter);
- /**
- * Get first filter in the chain.
- *
- * @deprecated This method will be removed in future versions. Please use
- * {@link #getCopyOfAttachedFiltersList()} method instead.
- */
- public Filter getFirstFilter();
-
public void clearAllFilters();
/**
diff --git a/logback-core/src/main/java/ch/qos/logback/core/spi/FilterAttachableImpl.java b/logback-core/src/main/java/ch/qos/logback/core/spi/FilterAttachableImpl.java
index 2b72bd4..3c84db6 100644
--- a/logback-core/src/main/java/ch/qos/logback/core/spi/FilterAttachableImpl.java
+++ b/logback-core/src/main/java/ch/qos/logback/core/spi/FilterAttachableImpl.java
@@ -36,17 +36,6 @@ final public class FilterAttachableImpl<E> implements FilterAttachable<E> {
}
/**
- * Get first filter in the chain.
- */
- public Filter<E> getFirstFilter() {
- if (filterList.size() > 0) {
- return filterList.get(0);
- } else {
- return null;
- }
- }
-
- /**
* Clear the filter chain
*/
public void clearAllFilters() {
diff --git a/logback-core/src/main/java/ch/qos/logback/core/util/FileUtil.java b/logback-core/src/main/java/ch/qos/logback/core/util/FileUtil.java
index 84e03af..2681140 100644
--- a/logback-core/src/main/java/ch/qos/logback/core/util/FileUtil.java
+++ b/logback-core/src/main/java/ch/qos/logback/core/util/FileUtil.java
@@ -25,7 +25,7 @@ import java.net.URLConnection;
public class FileUtil {
- static public boolean mustCreateParentDirectories(File file) {
+ static public boolean isParentDirectoryCreationRequired(File file) {
File parent = file.getParentFile();
if (parent != null && !parent.exists()) {
return true;
@@ -36,7 +36,7 @@ public class FileUtil {
static public boolean createMissingParentDirectories(File file) {
File parent = file.getParentFile();
- if (parent == null || parent.exists()) {
+ if (parent == null) {
throw new IllegalStateException(file + " should not have a null parent");
}
if (parent.exists()) {
diff --git a/logback-core/src/test/java/ch/qos/logback/core/appender/FileAppenderTest.java b/logback-core/src/test/java/ch/qos/logback/core/appender/FileAppenderTest.java
index d3022ed..c17a6cc 100644
--- a/logback-core/src/test/java/ch/qos/logback/core/appender/FileAppenderTest.java
+++ b/logback-core/src/test/java/ch/qos/logback/core/appender/FileAppenderTest.java
@@ -84,7 +84,7 @@ public class FileAppenderTest extends AbstractAppenderTest<Object> {
appender.start();
appender.doAppend(new Object());
appender.stop();
- assertFalse(FileUtil.mustCreateParentDirectories(file));
+ assertFalse(FileUtil.isParentDirectoryCreationRequired(file));
assertTrue(file.exists());
// cleanup
diff --git a/logback-core/src/test/java/ch/qos/logback/core/rolling/DelayerUtil.java b/logback-core/src/test/java/ch/qos/logback/core/rolling/DelayerUtil.java
deleted file mode 100644
index 995c768..0000000
--- a/logback-core/src/test/java/ch/qos/logback/core/rolling/DelayerUtil.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/**
- * Logback: the reliable, generic, fast and flexible logging framework.
- * Copyright (C) 1999-2009, QOS.ch. All rights reserved.
- *
- * This program and the accompanying materials are dual-licensed under
- * either the terms of the Eclipse Public License v1.0 as published by
- * the Eclipse Foundation
- *
- * or (per the licensee's choosing)
- *
- * under the terms of the GNU Lesser General Public License version 2.1
- * as published by the Free Software Foundation.
- */
-package ch.qos.logback.core.rolling;
-
-import java.util.Calendar;
-import java.util.Date;
-
-public class DelayerUtil {
-
- // delay until millis in the next second
- static void delayUntilNextSecond(int millis) {
- long now = System.currentTimeMillis();
- Calendar cal = Calendar.getInstance();
- cal.setTime(new Date(now));
-
- cal.set(Calendar.MILLISECOND, millis);
- cal.add(Calendar.SECOND, 1);
-
- long next = cal.getTime().getTime();
-
- try {
- Thread.sleep(next - now);
- } catch (Exception e) {
- }
- }
-
- static 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) {
- }
- }
-}
diff --git a/logback-core/src/test/java/ch/qos/logback/core/rolling/PackageTest.java b/logback-core/src/test/java/ch/qos/logback/core/rolling/PackageTest.java
index 94e8ca5..c9d64df 100644
--- a/logback-core/src/test/java/ch/qos/logback/core/rolling/PackageTest.java
+++ b/logback-core/src/test/java/ch/qos/logback/core/rolling/PackageTest.java
@@ -17,7 +17,7 @@ import org.junit.runner.RunWith;
import org.junit.runners.Suite;
@RunWith(Suite.class)
- at Suite.SuiteClasses( { RenamingTest.class, SizeBasedRollingTest.class,
+ at Suite.SuiteClasses( { RenameUtilTest.class, SizeBasedRollingTest.class,
TimeBasedRollingTest.class, TimeBasedRollingWithArchiveRemovalTest.class,
MultiThreadedRollingTest.class,
SizeAndTimeBasedFNATP_Test.class,
diff --git a/logback-core/src/test/java/ch/qos/logback/core/rolling/RenameUtilTest.java b/logback-core/src/test/java/ch/qos/logback/core/rolling/RenameUtilTest.java
new file mode 100644
index 0000000..282974c
--- /dev/null
+++ b/logback-core/src/test/java/ch/qos/logback/core/rolling/RenameUtilTest.java
@@ -0,0 +1,123 @@
+/**
+ * Logback: the reliable, generic, fast and flexible logging framework.
+ * Copyright (C) 1999-2009, QOS.ch. All rights reserved.
+ *
+ * This program and the accompanying materials are dual-licensed under
+ * either the terms of the Eclipse Public License v1.0 as published by
+ * the Eclipse Foundation
+ *
+ * or (per the licensee's choosing)
+ *
+ * under the terms of the GNU Lesser General Public License version 2.1
+ * as published by the Free Software Foundation.
+ */
+package ch.qos.logback.core.rolling;
+
+import static junit.framework.Assert.fail;
+import static org.junit.Assert.assertTrue;
+
+import java.io.File;
+import java.io.IOException;
+import java.text.SimpleDateFormat;
+
+import ch.qos.logback.core.CoreConstants;
+import ch.qos.logback.core.rolling.helper.RenameUtil;
+import ch.qos.logback.core.status.StatusChecker;
+import ch.qos.logback.core.testUtil.RandomUtil;
+import ch.qos.logback.core.util.StatusPrinter;
+import org.junit.Before;
+import org.junit.Test;
+
+import ch.qos.logback.core.Context;
+import ch.qos.logback.core.ContextBase;
+import ch.qos.logback.core.encoder.EchoEncoder;
+import ch.qos.logback.core.encoder.Encoder;
+import ch.qos.logback.core.util.Compare;
+import ch.qos.logback.core.util.CoreTestConstants;
+
+public class RenameUtilTest {
+
+ Encoder<Object> encoder;
+ Context context = new ContextBase();
+ StatusChecker statusChecker = new StatusChecker(context);
+
+ long currentTime = System.currentTimeMillis();
+ int diff = RandomUtil.getPositiveInt();
+ protected String randomOutputDirAsStr = CoreTestConstants.OUTPUT_DIR_PREFIX + diff
+ + "/";
+ protected File randomOutputDir = new File(randomOutputDirAsStr);
+
+ @Before
+ public void setUp() throws Exception {
+ encoder = new EchoEncoder<Object>();
+ // if this this the fist test run after 'build clean up' then the
+ // OUTPUT_DIR_PREFIX might be not yet created
+ randomOutputDir.mkdirs();
+ }
+
+
+ /**
+ * This test case aims to unit test/reproduce problems encountered while
+ * renaming the log file under windows. However, it is not clear how
+ * the test lives up to this claim.
+ */
+ @Test
+ public void rename() throws Exception {
+ RollingFileAppender<Object> rfa = new RollingFileAppender<Object>();
+ rfa.setEncoder(encoder);
+ rfa.setContext(context);
+
+ // rollover by the second
+ String datePattern = "yyyy-MM-dd_HH_mm_ss";
+ SimpleDateFormat sdf = new SimpleDateFormat(datePattern);
+ String[] filenames = new String[2];
+
+ TimeBasedRollingPolicy tbrp = new TimeBasedRollingPolicy();
+ tbrp.setFileNamePattern(randomOutputDirAsStr + "test-%d{"
+ + datePattern + "}");
+ tbrp.setContext(context);
+ tbrp.setParent(rfa);
+ tbrp.start();
+
+ TimeBasedFileNamingAndTriggeringPolicy tbnatp = tbrp
+ .getTimeBasedFileNamingAndTriggeringPolicy();
+ tbnatp.setCurrentTime(currentTime);
+
+ rfa.setRollingPolicy(tbrp);
+ rfa.start();
+
+ rfa.doAppend("Hello 0");
+
+ filenames[0] = randomOutputDirAsStr + "test-" + sdf.format(currentTime);
+
+ // set currentTime to next second plus 50 millis
+ currentTime += 1000 - (currentTime % 1000) + 50;
+ tbnatp.setCurrentTime(currentTime);
+
+ rfa.doAppend("Hello 1");
+
+ filenames[1] = randomOutputDirAsStr + "test-" + sdf.format(currentTime);
+
+ for (int i = 0; i < filenames.length; i++) {
+ assertTrue(Compare.compare(filenames[i], CoreTestConstants.TEST_DIR_PREFIX
+ + "witness/rolling/renaming." + i));
+ }
+ }
+
+ @Test
+ public void renameToNonExistingDirectory() throws IOException, RolloverFailure {
+ RenameUtil renameUtil = new RenameUtil();
+ renameUtil.setContext(context);
+
+ int diff2 = RandomUtil.getPositiveInt();
+ File fromFile = File.createTempFile("from" + diff, "test",
+ randomOutputDir);
+
+ String randomTARGETDir = CoreTestConstants.OUTPUT_DIR_PREFIX+diff2;
+
+ renameUtil.rename(fromFile.toString(), new File(randomTARGETDir + "/to.test").toString());
+ StatusPrinter.printInCaseOfErrorsOrWarnings(context);
+ assertTrue(statusChecker.isErrorFree());
+ }
+
+}
diff --git a/logback-core/src/test/java/ch/qos/logback/core/rolling/RenamingTest.java b/logback-core/src/test/java/ch/qos/logback/core/rolling/RenamingTest.java
deleted file mode 100644
index b1e43e1..0000000
--- a/logback-core/src/test/java/ch/qos/logback/core/rolling/RenamingTest.java
+++ /dev/null
@@ -1,96 +0,0 @@
-/**
- * Logback: the reliable, generic, fast and flexible logging framework.
- * Copyright (C) 1999-2009, QOS.ch. All rights reserved.
- *
- * This program and the accompanying materials are dual-licensed under
- * either the terms of the Eclipse Public License v1.0 as published by
- * the Eclipse Foundation
- *
- * or (per the licensee's choosing)
- *
- * under the terms of the GNU Lesser General Public License version 2.1
- * as published by the Free Software Foundation.
- */
-package ch.qos.logback.core.rolling;
-
-import static org.junit.Assert.assertTrue;
-
-import java.io.File;
-import java.text.SimpleDateFormat;
-import java.util.Calendar;
-
-import org.junit.Before;
-import org.junit.Test;
-
-import ch.qos.logback.core.Context;
-import ch.qos.logback.core.ContextBase;
-import ch.qos.logback.core.encoder.EchoEncoder;
-import ch.qos.logback.core.encoder.Encoder;
-import ch.qos.logback.core.util.Compare;
-import ch.qos.logback.core.util.CoreTestConstants;
-
-/**
- *
- * This test case aims to unit test/reproduce problems encountered while
- * renaming the log file under windows.
- *
- * @author Ceki
- *
- */
-public class RenamingTest {
-
- Encoder<Object> encoder;
- Context context = new ContextBase();
-
- @Before
- public void setUp() throws Exception {
- encoder = new EchoEncoder<Object>();
-
- File target = new File(CoreTestConstants.OUTPUT_DIR_PREFIX + "test.log");
- target.mkdirs();
- target.delete();
- }
-
- @Test
- public void testRename() throws Exception {
-
- RollingFileAppender<Object> rfa = new RollingFileAppender<Object>();
- rfa.setEncoder(encoder);
- rfa.setContext(context);
-
- // rollover by the second
- String datePattern = "yyyy-MM-dd_HH_mm_ss";
- SimpleDateFormat sdf = new SimpleDateFormat(datePattern);
- String[] filenames = new String[2];
-
- TimeBasedRollingPolicy tbrp = new TimeBasedRollingPolicy();
- tbrp.setFileNamePattern(CoreTestConstants.OUTPUT_DIR_PREFIX + "test-%d{"
- + datePattern + "}");
- tbrp.setContext(context);
- tbrp.setParent(rfa);
- tbrp.start();
-
- rfa.setRollingPolicy(tbrp);
- rfa.start();
-
-
- Calendar cal0 = Calendar.getInstance();
- rfa.doAppend("Hello 0");
-
- DelayerUtil.delayUntilNextSecond(50);
-
- Calendar cal1 = Calendar.getInstance();
- rfa.doAppend("Hello 1");
-
- filenames[0] = CoreTestConstants.OUTPUT_DIR_PREFIX + "test-"
- + sdf.format(cal0.getTime());
- filenames[1] = CoreTestConstants.OUTPUT_DIR_PREFIX + "test-"
- + sdf.format(cal1.getTime());
-
-
- for (int i = 0; i < filenames.length; i++) {
- assertTrue(Compare.compare(filenames[i], CoreTestConstants.TEST_DIR_PREFIX
- + "witness/rolling/renaming." + i));
- }
- }
-}
diff --git a/logback-core/src/test/java/ch/qos/logback/core/rolling/ScaffoldingForRollingTests.java b/logback-core/src/test/java/ch/qos/logback/core/rolling/ScaffoldingForRollingTests.java
index 633e1db..3993f82 100644
--- a/logback-core/src/test/java/ch/qos/logback/core/rolling/ScaffoldingForRollingTests.java
+++ b/logback-core/src/test/java/ch/qos/logback/core/rolling/ScaffoldingForRollingTests.java
@@ -38,19 +38,18 @@ import ch.qos.logback.core.util.CoreTestConstants;
/**
* Scaffolding for various rolling tests. Some assumptions are made: - rollover
* periodicity is 1 second (without precluding size based roll-over)
- *
+ *
* @author Ceki Gülcü
- *
*/
public class ScaffoldingForRollingTests {
static public final String DATE_PATTERN_WITH_SECONDS = "yyyy-MM-dd_HH_mm_ss";
static public final SimpleDateFormat SDF = new SimpleDateFormat(
- DATE_PATTERN_WITH_SECONDS);
+ DATE_PATTERN_WITH_SECONDS);
int diff = RandomUtil.getPositiveInt();
protected String randomOutputDir = CoreTestConstants.OUTPUT_DIR_PREFIX + diff
- + "/";
+ + "/";
EchoEncoder<Object> encoder = new EchoEncoder<Object>();
Context context = new ContextBase();
protected List<String> expectedFilenameList = new ArrayList<String>();
@@ -68,7 +67,7 @@ public class ScaffoldingForRollingTests {
public static void existenceCheck(String filename) {
assertTrue("File " + filename + " does not exist", new File(filename)
- .exists());
+ .exists());
}
public static File[] getFilesInDirectory(String outputDirStr) {
@@ -77,7 +76,7 @@ public class ScaffoldingForRollingTests {
}
public static void fileContentCheck(File[] fileArray, int runLength,
- String prefix) throws IOException {
+ String prefix) throws IOException {
List<String> stringList = new ArrayList<String>();
for (File file : fileArray) {
FileToBufferUtil.readIntoList(file, stringList);
@@ -92,14 +91,14 @@ public class ScaffoldingForRollingTests {
}
public static void sortedContentCheck(String outputDirStr, int runLength,
- String prefix) throws IOException {
+ String prefix) throws IOException {
File[] fileArray = getFilesInDirectory(outputDirStr);
FileFilterUtil.sortFileArrayByName(fileArray);
fileContentCheck(fileArray, runLength, prefix);
}
public static void reverseSortedContentCheck(String outputDirStr,
- int runLength, String prefix) throws IOException {
+ int runLength, String prefix) throws IOException {
File[] fileArray = getFilesInDirectory(outputDirStr);
FileFilterUtil.reverseSortFileArrayByName(fileArray);
fileContentCheck(fileArray, runLength, prefix);
@@ -108,7 +107,7 @@ public class ScaffoldingForRollingTests {
public static void existenceCheck(List<String> filenameList) {
for (String filename : filenameList) {
assertTrue("File " + filename + " does not exist", new File(filename)
- .exists());
+ .exists());
}
}
@@ -127,6 +126,7 @@ public class ScaffoldingForRollingTests {
}
// assuming rollover every second
+
protected void recomputeRolloverThreshold(long ct) {
long delta = ct % 1000;
nextRolloverThreshold = (ct - delta) + 1000;
@@ -151,27 +151,27 @@ public class ScaffoldingForRollingTests {
}
static void waitForCompression(TimeBasedRollingPolicy<Object> tbrp)
- throws InterruptedException, ExecutionException, TimeoutException {
+ throws InterruptedException, ExecutionException, TimeoutException {
if (tbrp.future != null && !tbrp.future.isDone()) {
tbrp.future.get(200, TimeUnit.MILLISECONDS);
}
}
- protected void addExpectedFileName_ByDate(String testId, Date date,
- boolean gzExtension) {
+ protected void addExpectedFileName_ByDate(String outputDir, String testId, Date date,
+ boolean gzExtension) {
- String fn = randomOutputDir + testId + "-" + SDF.format(date);
+ String fn = outputDir + testId + "-" + SDF.format(date);
if (gzExtension) {
fn += ".gz";
}
expectedFilenameList.add(fn);
}
- protected void addExpectedFileNamedIfItsTime_ByDate(String testId,
- boolean gzExtension) {
+ protected void addExpectedFileNamedIfItsTime_ByDate(String outputDir, String testId,
+ boolean gzExtension) {
if (passThresholdTime(nextRolloverThreshold)) {
- addExpectedFileName_ByDate(testId, getDateOfCurrentPeriodsStart(),
- gzExtension);
+ addExpectedFileName_ByDate(outputDir, testId, getDateOfCurrentPeriodsStart(),
+ gzExtension);
recomputeRolloverThreshold(currentTime);
}
}
diff --git a/logback-core/src/test/java/ch/qos/logback/core/rolling/TimeBasedRollingTest.java b/logback-core/src/test/java/ch/qos/logback/core/rolling/TimeBasedRollingTest.java
index f76cac4..f918e73 100644
--- a/logback-core/src/test/java/ch/qos/logback/core/rolling/TimeBasedRollingTest.java
+++ b/logback-core/src/test/java/ch/qos/logback/core/rolling/TimeBasedRollingTest.java
@@ -17,6 +17,8 @@ import static org.junit.Assert.assertTrue;
import java.io.File;
+import ch.qos.logback.core.testUtil.RandomUtil;
+import ch.qos.logback.core.util.StatusPrinter;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -28,21 +30,21 @@ import ch.qos.logback.core.util.CoreTestConstants;
* A rather exhaustive set of tests. Tests include leaving the file option
* blank, or setting it, with and without compression, and tests with or without
* stopping/restarting the RollingFileAppender.
- *
+ * <p/>
* The regression tests log a few times using a RollingFileAppender. Then, they
* predict the names of the files which should be generated and compare them
* with witness files.
- *
+ * <p/>
* <pre>
- * Compression file option Stop/Restart
+ * Compression file option Stop/Restart
* Test1 NO BLANK NO
* Test2 YES BLANK NO
* Test3 NO BLANK YES
- * Test4 NO SET YES
+ * Test4 NO SET YES
* Test5 NO SET NO
* Test6 YES SET NO
* </pre>
- *
+ *
* @author Ceki Gülcü
*/
public class TimeBasedRollingTest extends ScaffoldingForRollingTests {
@@ -72,8 +74,8 @@ public class TimeBasedRollingTest extends ScaffoldingForRollingTests {
}
void initTRBP(RollingFileAppender<Object> rfa,
- TimeBasedRollingPolicy<Object> tbrp, String filenamePattern,
- long givenTime) {
+ TimeBasedRollingPolicy<Object> tbrp, String filenamePattern,
+ long givenTime) {
tbrp.setContext(context);
tbrp.setFileNamePattern(filenamePattern);
tbrp.setParent(rfa);
@@ -92,17 +94,17 @@ public class TimeBasedRollingTest extends ScaffoldingForRollingTests {
String testId = "test1";
initRFA(rfa1, null);
initTRBP(rfa1, tbrp1, randomOutputDir + testId + "-%d{"
- + DATE_PATTERN_WITH_SECONDS + "}", currentTime);
+ + DATE_PATTERN_WITH_SECONDS + "}", currentTime);
// compute the current filename
- addExpectedFileName_ByDate(testId, getDateOfCurrentPeriodsStart(), false);
+ addExpectedFileName_ByDate(randomOutputDir, testId, getDateOfCurrentPeriodsStart(), false);
incCurrentTime(1100);
tbrp1.timeBasedTriggering.setCurrentTime(currentTime);
for (int i = 0; i < 3; i++) {
rfa1.doAppend("Hello---" + i);
- addExpectedFileNamedIfItsTime_ByDate(testId, false);
+ addExpectedFileNamedIfItsTime_ByDate(randomOutputDir, testId, false);
incCurrentTime(500);
tbrp1.timeBasedTriggering.setCurrentTime(currentTime);
}
@@ -110,7 +112,7 @@ public class TimeBasedRollingTest extends ScaffoldingForRollingTests {
int i = 0;
for (String fn : expectedFilenameList) {
assertTrue(Compare.compare(fn, CoreTestConstants.TEST_DIR_PREFIX
- + "witness/rolling/tbr-" + testId + "." + i++));
+ + "witness/rolling/tbr-" + testId + "." + i++));
}
}
@@ -122,15 +124,15 @@ public class TimeBasedRollingTest extends ScaffoldingForRollingTests {
String testId = "test2";
initRFA(rfa1, null);
initTRBP(rfa1, tbrp1, randomOutputDir + testId + "-%d{"
- + DATE_PATTERN_WITH_SECONDS + "}.gz", currentTime);
+ + DATE_PATTERN_WITH_SECONDS + "}.gz", currentTime);
- addExpectedFileName_ByDate(testId, getDateOfCurrentPeriodsStart(), true);
+ addExpectedFileName_ByDate(randomOutputDir, testId, getDateOfCurrentPeriodsStart(), true);
incCurrentTime(1100);
tbrp1.timeBasedTriggering.setCurrentTime(currentTime);
for (int i = 0; i < 3; i++) {
// when i == 2, file name should not have .gz extension
- addExpectedFileNamedIfItsTime_ByDate(testId, i != 2);
+ addExpectedFileNamedIfItsTime_ByDate(randomOutputDir, testId, i != 2);
rfa1.doAppend("Hello---" + i);
incCurrentTime(500);
tbrp1.timeBasedTriggering.setCurrentTime(currentTime);
@@ -140,7 +142,7 @@ public class TimeBasedRollingTest extends ScaffoldingForRollingTests {
int i = 0;
for (String fn : expectedFilenameList) {
assertTrue(Compare.compare(fn, CoreTestConstants.TEST_DIR_PREFIX
- + "witness/rolling/tbr-" + testId + "." + i + addGZIfNotLast(i)));
+ + "witness/rolling/tbr-" + testId + "." + i + addGZIfNotLast(i)));
i++;
}
}
@@ -154,17 +156,17 @@ public class TimeBasedRollingTest extends ScaffoldingForRollingTests {
initRFA(rfa1, null);
initTRBP(rfa1, tbrp1, randomOutputDir + testId + "-%d{"
- + DATE_PATTERN_WITH_SECONDS + "}", currentTime);
+ + DATE_PATTERN_WITH_SECONDS + "}", currentTime);
// a new file is created by virtue of rfa.start();
- addExpectedFileName_ByDate(testId, getDateOfCurrentPeriodsStart(), false);
+ addExpectedFileName_ByDate(randomOutputDir, testId, getDateOfCurrentPeriodsStart(), false);
incCurrentTime(1100);
tbrp1.timeBasedTriggering.setCurrentTime(currentTime);
for (int i = 0; i <= 2; i++) {
rfa1.doAppend("Hello---" + i);
- addExpectedFileNamedIfItsTime_ByDate(testId, false);
+ addExpectedFileNamedIfItsTime_ByDate(randomOutputDir, testId, false);
incCurrentTime(500);
tbrp1.timeBasedTriggering.setCurrentTime(currentTime);
}
@@ -173,11 +175,11 @@ public class TimeBasedRollingTest extends ScaffoldingForRollingTests {
initRFA(rfa2, null);
initTRBP(rfa2, tbrp2, randomOutputDir + testId + "-%d{"
- + DATE_PATTERN_WITH_SECONDS + "}", tbrp1.timeBasedTriggering
- .getCurrentTime());
+ + DATE_PATTERN_WITH_SECONDS + "}", tbrp1.timeBasedTriggering
+ .getCurrentTime());
for (int i = 0; i <= 2; i++) {
- addExpectedFileNamedIfItsTime_ByDate(testId, false);
+ addExpectedFileNamedIfItsTime_ByDate(randomOutputDir, testId, false);
rfa2.doAppend("World---" + i);
incCurrentTime(100);
tbrp2.timeBasedTriggering.setCurrentTime(currentTime);
@@ -186,7 +188,7 @@ public class TimeBasedRollingTest extends ScaffoldingForRollingTests {
int i = 0;
for (String fn : expectedFilenameList) {
assertTrue(Compare.compare(fn, CoreTestConstants.TEST_DIR_PREFIX
- + "witness/rolling/tbr-" + testId + "." + i++));
+ + "witness/rolling/tbr-" + testId + "." + i++));
}
}
@@ -198,16 +200,16 @@ public class TimeBasedRollingTest extends ScaffoldingForRollingTests {
String testId = "test4";
initRFA(rfa1, testId2FileName(testId));
initTRBP(rfa1, tbrp1, randomOutputDir + testId + "-%d{"
- + DATE_PATTERN_WITH_SECONDS + "}", currentTime);
+ + DATE_PATTERN_WITH_SECONDS + "}", currentTime);
- addExpectedFileName_ByDate(testId, getDateOfCurrentPeriodsStart(), false);
+ addExpectedFileName_ByDate(randomOutputDir, testId, getDateOfCurrentPeriodsStart(), false);
incCurrentTime(1100);
tbrp1.timeBasedTriggering.setCurrentTime(currentTime);
for (int i = 0; i <= 2; i++) {
rfa1.doAppend("Hello---" + i);
- addExpectedFileNamedIfItsTime_ByDate(testId, false);
+ addExpectedFileNamedIfItsTime_ByDate(randomOutputDir, testId, false);
incCurrentTime(500);
tbrp1.timeBasedTriggering.setCurrentTime(currentTime);
}
@@ -220,11 +222,11 @@ public class TimeBasedRollingTest extends ScaffoldingForRollingTests {
initRFA(rfa2, testId2FileName(testId));
initTRBP(rfa2, tbrp2, randomOutputDir + testId + "-%d{"
- + DATE_PATTERN_WITH_SECONDS + "}", currentTime);
+ + DATE_PATTERN_WITH_SECONDS + "}", currentTime);
for (int i = 0; i <= 2; i++) {
rfa2.doAppend("World---" + i);
- addExpectedFileNamedIfItsTime_ByDate(testId, false);
+ addExpectedFileNamedIfItsTime_ByDate(randomOutputDir, testId, false);
incCurrentTime(100);
tbrp2.timeBasedTriggering.setCurrentTime(currentTime);
}
@@ -234,26 +236,26 @@ public class TimeBasedRollingTest extends ScaffoldingForRollingTests {
int i = 0;
for (String fn : expectedFilenameList) {
assertTrue(Compare.compare(fn, CoreTestConstants.TEST_DIR_PREFIX
- + "witness/rolling/tbr-" + testId + "." + i++));
+ + "witness/rolling/tbr-" + testId + "." + i++));
}
}
@Test
public void noCompression_FileSet_StopRestart_WithLongWait_4B()
- throws Exception {
+ throws Exception {
String testId = "test4B";
initRFA(rfa1, testId2FileName(testId));
initTRBP(rfa1, tbrp1, randomOutputDir + testId + "-%d{"
- + DATE_PATTERN_WITH_SECONDS + "}", currentTime);
+ + DATE_PATTERN_WITH_SECONDS + "}", currentTime);
- addExpectedFileName_ByDate(testId, getDateOfCurrentPeriodsStart(), false);
+ addExpectedFileName_ByDate(randomOutputDir, testId, getDateOfCurrentPeriodsStart(), false);
incCurrentTime(1100);
tbrp1.timeBasedTriggering.setCurrentTime(currentTime);
for (int i = 0; i <= 2; i++) {
rfa1.doAppend("Hello---" + i);
- addExpectedFileNamedIfItsTime_ByDate(testId, false);
+ addExpectedFileNamedIfItsTime_ByDate(randomOutputDir, testId, false);
incCurrentTime(500);
tbrp1.timeBasedTriggering.setCurrentTime(currentTime);
}
@@ -268,11 +270,11 @@ public class TimeBasedRollingTest extends ScaffoldingForRollingTests {
initRFA(rfa2, randomOutputDir + "test4B.log");
initTRBP(rfa2, tbrp2, randomOutputDir + testId + "-%d{"
- + DATE_PATTERN_WITH_SECONDS + "}", currentTime);
+ + DATE_PATTERN_WITH_SECONDS + "}", currentTime);
for (int i = 0; i <= 2; i++) {
rfa2.doAppend("World---" + i);
- addExpectedFileNamedIfItsTime_ByDate(testId, false);
+ addExpectedFileNamedIfItsTime_ByDate(randomOutputDir, testId, false);
incCurrentTime(100);
tbrp2.timeBasedTriggering.setCurrentTime(currentTime);
}
@@ -282,7 +284,7 @@ public class TimeBasedRollingTest extends ScaffoldingForRollingTests {
int i = 0;
for (String fn : expectedFilenameList) {
assertTrue(Compare.compare(fn, CoreTestConstants.TEST_DIR_PREFIX
- + "witness/rolling/tbr-test4B." + i++));
+ + "witness/rolling/tbr-test4B." + i++));
}
}
@@ -296,16 +298,16 @@ public class TimeBasedRollingTest extends ScaffoldingForRollingTests {
initRFA(rfa1, testId2FileName(testId));
initTRBP(rfa1, tbrp1, randomOutputDir + testId + "-%d{"
- + DATE_PATTERN_WITH_SECONDS + "}", currentTime);
+ + DATE_PATTERN_WITH_SECONDS + "}", currentTime);
- addExpectedFileName_ByDate(testId, getDateOfCurrentPeriodsStart(), false);
+ addExpectedFileName_ByDate(randomOutputDir, testId, getDateOfCurrentPeriodsStart(), false);
incCurrentTime(1100);
tbrp1.timeBasedTriggering.setCurrentTime(currentTime);
for (int i = 0; i < 3; i++) {
rfa1.doAppend("Hello---" + i);
- addExpectedFileNamedIfItsTime_ByDate(testId, false);
+ addExpectedFileNamedIfItsTime_ByDate(randomOutputDir, testId, false);
incCurrentTime(500);
tbrp1.timeBasedTriggering.setCurrentTime(currentTime);
}
@@ -315,7 +317,7 @@ public class TimeBasedRollingTest extends ScaffoldingForRollingTests {
int i = 0;
for (String fn : expectedFilenameList) {
assertTrue(Compare.compare(fn, CoreTestConstants.TEST_DIR_PREFIX
- + "witness/rolling/tbr-test5." + i++));
+ + "witness/rolling/tbr-test5." + i++));
}
}
@@ -329,16 +331,16 @@ public class TimeBasedRollingTest extends ScaffoldingForRollingTests {
initRFA(rfa1, testId2FileName(testId));
initTRBP(rfa1, tbrp1, randomOutputDir + testId + "-%d{"
- + DATE_PATTERN_WITH_SECONDS + "}.gz", currentTime);
+ + DATE_PATTERN_WITH_SECONDS + "}.gz", currentTime);
- addExpectedFileName_ByDate(testId, getDateOfCurrentPeriodsStart(), true);
+ addExpectedFileName_ByDate(randomOutputDir, testId, getDateOfCurrentPeriodsStart(), true);
incCurrentTime(1100);
tbrp1.timeBasedTriggering.setCurrentTime(currentTime);
for (int i = 0; i < 3; i++) {
rfa1.doAppend("Hello---" + i);
- addExpectedFileNamedIfItsTime_ByDate(testId, true);
+ addExpectedFileNamedIfItsTime_ByDate(randomOutputDir, testId, true);
incCurrentTime(500);
tbrp1.timeBasedTriggering.setCurrentTime(currentTime);
waitForCompression(tbrp1);
@@ -349,11 +351,46 @@ public class TimeBasedRollingTest extends ScaffoldingForRollingTests {
int i = 0;
for (String fn : expectedFilenameList) {
assertTrue(Compare.compare(fn, CoreTestConstants.TEST_DIR_PREFIX
- + "witness/rolling/tbr-" + testId + "." + i + addGZIfNotLast(i)));
+ + "witness/rolling/tbr-" + testId + "." + i + addGZIfNotLast(i)));
i++;
}
}
+ @Test
+ public void withMissingTargetDir() throws Exception {
+ String testId = "missingTargetDir";
+
+ initRFA(rfa1, testId2FileName(testId));
+ int secondDiff = RandomUtil.getPositiveInt();
+ String randomTargetDir = CoreTestConstants.OUTPUT_DIR_PREFIX + secondDiff + '/';
+
+ System.out.println("randomOutputDir"+randomOutputDir);
+ System.out.println("randomTargetDir"+randomTargetDir);
+
+ initTRBP(rfa1, tbrp1, randomTargetDir + testId + "-%d{"
+ + DATE_PATTERN_WITH_SECONDS + "}", currentTime);
+
+ addExpectedFileName_ByDate(randomTargetDir, testId, getDateOfCurrentPeriodsStart(), false);
+
+ incCurrentTime(1100);
+ tbrp1.timeBasedTriggering.setCurrentTime(currentTime);
+
+ for (int i = 0; i < 3; i++) {
+ rfa1.doAppend("Hello---" + i);
+ addExpectedFileNamedIfItsTime_ByDate(randomTargetDir, testId, false);
+ incCurrentTime(500);
+ tbrp1.timeBasedTriggering.setCurrentTime(currentTime);
+ }
+ massageExpectedFilesToCorresponToCurrentTarget("missingTargetDir.log");
+ int i = 0;
+ for (String fn : expectedFilenameList) {
+ System.out.println("expectedFile="+fn);
+ assertTrue(Compare.compare(fn, CoreTestConstants.TEST_DIR_PREFIX
+ + "witness/rolling/tbr-test5." + i++));
+ }
+
+ }
+
// =========================================================================
// utility methods
// =========================================================================
diff --git a/logback-core/src/test/java/ch/qos/logback/core/util/FileUtilTest.java b/logback-core/src/test/java/ch/qos/logback/core/util/FileUtilTest.java
index b392c91..23b072f 100644
--- a/logback-core/src/test/java/ch/qos/logback/core/util/FileUtilTest.java
+++ b/logback-core/src/test/java/ch/qos/logback/core/util/FileUtilTest.java
@@ -51,9 +51,9 @@ public class FileUtilTest {
cleanupList.add(file);
cleanupList.add(file.getParentFile());
- assertTrue(FileUtil.mustCreateParentDirectories(file));
+ assertTrue(FileUtil.isParentDirectoryCreationRequired(file));
assertTrue(FileUtil.createMissingParentDirectories(file));
- assertFalse(FileUtil.mustCreateParentDirectories(file));
+ assertFalse(FileUtil.isParentDirectoryCreationRequired(file));
}
@Test
@@ -65,8 +65,8 @@ public class FileUtilTest {
cleanupList.add(file.getParentFile());
cleanupList.add(file.getParentFile().getParentFile());
- assertTrue(FileUtil.mustCreateParentDirectories(file));
+ assertTrue(FileUtil.isParentDirectoryCreationRequired(file));
assertTrue(FileUtil.createMissingParentDirectories(file));
- assertFalse(FileUtil.mustCreateParentDirectories(file));
+ assertFalse(FileUtil.isParentDirectoryCreationRequired(file));
}
}
diff --git a/logback-site/src/site/pages/news.html b/logback-site/src/site/pages/news.html
index 398366a..7689704 100644
--- a/logback-site/src/site/pages/news.html
+++ b/logback-site/src/site/pages/news.html
@@ -30,7 +30,7 @@
<h3>April xx, 2010 - Release of version 0.9.21</h3>
- <p>SLF4J dependency upgraded to 1.6.0-RC0.</p>
+ <p>SLF4J dependency upgraded to 1.6.0</p>
<p>Fixed concurrency problem in <code>SiftingAppender</code> as
reported in <a
@@ -43,6 +43,12 @@
which processes boolean expression written in the Groovy language.
</p>
+ <p>Fixed rollover problem occuring when the target directory was
+ missing as reported in <a
+ href="http://jira.qos.ch/browse/LBCORE-151">LBCORE-151</a> by
+ Torsten Juergeleit.
+ </p>
+
<hr width="80%" align="center" />
@@ -71,6 +77,8 @@
href="http://jira.qos.ch/browse/LBCLASSIC-87">LBCLASSIC-87</a>.
</p>
+ <p>Removed the previously deprecated <code>getFirstFilter</code>
+ method in <code>FilterAttachable</code> interface.</p>
<!-- ============================================================== -->
http://git.qos.ch/gitweb/?p=logback.git;a=commit;h=cbd336b71ef1842babf7ccdcf59e63861beef0ab
http://github.com/ceki/logback/commit/cbd336b71ef1842babf7ccdcf59e63861beef0ab
commit cbd336b71ef1842babf7ccdcf59e63861beef0ab
Author: Ceki Gulcu <ceki at qos.ch>
Date: Sat May 8 14:58:09 2010 +0200
- upgrade to SLF4J 1.6.0
- minor corrections
diff --git a/logback-classic/src/test/java/ch/qos/logback/classic/LoggerContextDeadlockTest.java b/logback-classic/src/test/java/ch/qos/logback/classic/LoggerContextDeadlockTest.java
index 954cf03..8c7a4ed 100644
--- a/logback-classic/src/test/java/ch/qos/logback/classic/LoggerContextDeadlockTest.java
+++ b/logback-classic/src/test/java/ch/qos/logback/classic/LoggerContextDeadlockTest.java
@@ -37,14 +37,14 @@ public class LoggerContextDeadlockTest {
public void tearDown() throws Exception {
}
- @Test(timeout=20000)
+ @Test(timeout = 20000)
public void testLBCLASSIC_81() throws JoranException {
getLoggerThread.start();
for (int i = 0; i < 500; i++) {
- ByteArrayInputStream baos = new ByteArrayInputStream(new String(
- "<configuration><root level=\"DEBUG\"/></configuration>").getBytes());
+ ByteArrayInputStream baos = new ByteArrayInputStream(
+ "<configuration><root level=\"DEBUG\"/></configuration>".getBytes());
jc.doConfigure(baos);
}
}
@@ -52,13 +52,15 @@ public class LoggerContextDeadlockTest {
class GetLoggerThread extends Thread {
final LoggerContext loggerContext;
+
GetLoggerThread(LoggerContext loggerContext) {
this.loggerContext = loggerContext;
}
+
@Override
public void run() {
for (int i = 0; i < 10000; i++) {
- if(i % 100 == 0) {
+ if (i % 100 == 0) {
try {
Thread.sleep(1);
} catch (InterruptedException e) {
diff --git a/logback-classic/src/test/java/ch/qos/logback/classic/html/HTMLLayoutTest.java b/logback-classic/src/test/java/ch/qos/logback/classic/html/HTMLLayoutTest.java
index 8c9cd2e..d3706ac 100644
--- a/logback-classic/src/test/java/ch/qos/logback/classic/html/HTMLLayoutTest.java
+++ b/logback-classic/src/test/java/ch/qos/logback/classic/html/HTMLLayoutTest.java
@@ -158,7 +158,7 @@ public class HTMLLayoutTest {
{
Element tdElement = (Element) trElement.elements().get(1);
String regex = ClassicTestConstants.NAKED_MAIN_REGEX;
- assertTrue(tdElement.getText().toString().matches(regex));
+ assertTrue(tdElement.getText().matches(regex));
}
{
Element tdElement = (Element) trElement.elements().get(2);
diff --git a/logback-core/src/main/java/ch/qos/logback/core/pattern/CompositeConverter.java b/logback-core/src/main/java/ch/qos/logback/core/pattern/CompositeConverter.java
index 824a349..667d409 100644
--- a/logback-core/src/main/java/ch/qos/logback/core/pattern/CompositeConverter.java
+++ b/logback-core/src/main/java/ch/qos/logback/core/pattern/CompositeConverter.java
@@ -43,7 +43,7 @@ public class CompositeConverter<E> extends FormattingConverter<E> {
buf.append(formattingInfo);
if (childConverter != null) {
- buf.append(", children: "+childConverter);
+ buf.append(", children: ").append(childConverter);
}
buf.append(">");
return buf.toString();
diff --git a/logback-core/src/test/java/ch/qos/logback/core/helpers/ThrowableToStringArrayTest.java b/logback-core/src/test/java/ch/qos/logback/core/helpers/ThrowableToStringArrayTest.java
index 05b5d18..d897591 100644
--- a/logback-core/src/test/java/ch/qos/logback/core/helpers/ThrowableToStringArrayTest.java
+++ b/logback-core/src/test/java/ch/qos/logback/core/helpers/ThrowableToStringArrayTest.java
@@ -43,7 +43,7 @@ public class ThrowableToStringArrayTest {
String[] sa = ThrowableToStringArray.convert(t);
StringBuilder sb = new StringBuilder();
for (String tdp : sa) {
- sb.append(tdp.toString());
+ sb.append(tdp);
sb.append(CoreConstants.LINE_SEPARATOR);
}
String expected = sw.toString();
diff --git a/pom.xml b/pom.xml
index 88076fc..788d523 100755
--- a/pom.xml
+++ b/pom.xml
@@ -43,7 +43,7 @@
<properties>
<!-- slf4j.version property is used below, in
logback-classic/pom.xml and in setClasspath.cmd -->
- <slf4j.version>1.6.0-alpha2</slf4j.version>
+ <slf4j.version>1.6.0</slf4j.version>
<consolePlugin.version>1.1.0</consolePlugin.version>
</properties>
-----------------------------------------------------------------------
Summary of changes:
.../qos/logback/access/jetty/RequestLogImpl.java | 3 -
.../logback/access/jetty/v7/RequestLogImpl.java | 4 -
.../ch/qos/logback/access/spi/AccessContext.java | 4 -
.../ch/qos/logback/access/tomcat/LogbackValve.java | 4 -
.../logback/classic/LoggerContextDeadlockTest.java | 10 +-
.../qos/logback/classic/html/HTMLLayoutTest.java | 2 +-
.../TimeBasedRollingWithConfigFileTest.java | 42 +++---
.../java/ch/qos/logback/core/AppenderBase.java | 4 -
.../java/ch/qos/logback/core/FileAppender.java | 2 +-
.../logback/core/UnsynchronizedAppenderBase.java | 4 -
.../logback/core/pattern/CompositeConverter.java | 2 +-
.../TimeBasedFileNamingAndTriggeringPolicy.java | 168 ++++++++++----------
.../core/rolling/TimeBasedRollingPolicy.java | 3 +-
.../logback/core/rolling/helper/RenameUtil.java | 38 +++--
.../ch/qos/logback/core/spi/FilterAttachable.java | 8 -
.../qos/logback/core/spi/FilterAttachableImpl.java | 11 --
.../java/ch/qos/logback/core/util/FileUtil.java | 4 +-
.../logback/core/appender/FileAppenderTest.java | 2 +-
.../core/helpers/ThrowableToStringArrayTest.java | 2 +-
.../ch/qos/logback/core/rolling/DelayerUtil.java | 53 ------
.../ch/qos/logback/core/rolling/PackageTest.java | 2 +-
.../qos/logback/core/rolling/RenameUtilTest.java | 123 ++++++++++++++
.../ch/qos/logback/core/rolling/RenamingTest.java | 96 -----------
.../core/rolling/ScaffoldingForRollingTests.java | 34 ++--
.../logback/core/rolling/TimeBasedRollingTest.java | 123 +++++++++-----
.../ch/qos/logback/core/util/FileUtilTest.java | 8 +-
logback-site/src/site/pages/news.html | 10 +-
pom.xml | 2 +-
28 files changed, 381 insertions(+), 387 deletions(-)
delete mode 100644 logback-core/src/test/java/ch/qos/logback/core/rolling/DelayerUtil.java
create mode 100644 logback-core/src/test/java/ch/qos/logback/core/rolling/RenameUtilTest.java
delete mode 100644 logback-core/src/test/java/ch/qos/logback/core/rolling/RenamingTest.java
hooks/post-receive
--
Logback: the generic, reliable, fast and flexible logging framework.
More information about the logback-dev
mailing list