[logback-dev] svn commit: r828 - in logback/trunk/logback-core/src: main/java/ch/qos/logback/core main/java/ch/qos/logback/core/joran/action main/java/ch/qos/logback/core/rolling test/java/ch/qos/logback/core/rolling
noreply.seb at qos.ch
noreply.seb at qos.ch
Tue Oct 31 21:42:26 CET 2006
Author: seb
Date: Tue Oct 31 21:42:25 2006
New Revision: 828
Modified:
logback/trunk/logback-core/src/main/java/ch/qos/logback/core/FileAppender.java
logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/action/NestedComponentIA.java
logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/FixedWindowRollingPolicy.java
logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/RollingFileAppender.java
logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/RollingPolicy.java
logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/RollingPolicyBase.java
logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/TimeBasedRollingPolicy.java
logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/RenamingTest.java
logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/SizeBasedRollingTest.java
logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/TimeBasedRollingTest.java
Log:
On going work.
Trying to remote the activeFileName/fileName dual information in logback configuration.
The current version works in some situations but not all, and does not passes all the tests.
Please use with caution if building logback from repository.
Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/FileAppender.java
==============================================================================
--- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/FileAppender.java (original)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/FileAppender.java Tue Oct 31 21:42:25 2006
@@ -31,7 +31,7 @@
protected boolean append = true;
/**
- * The name of the log file.
+ * The name of the active log file.
*/
protected String fileName = null;
Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/action/NestedComponentIA.java
==============================================================================
--- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/action/NestedComponentIA.java (original)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/action/NestedComponentIA.java Tue Oct 31 21:42:25 2006
@@ -129,11 +129,11 @@
return;
}
-// PropertySetter nestedBean = new PropertySetter(actionData.nestedComponent);
+ PropertySetter nestedBean = new PropertySetter(actionData.nestedComponent);
-// FIXME
-// nestedBean.setComponent(
-// "parent", actionData.parentBean.getObj());
+// FIXME set parent
+ nestedBean.setComponent(
+ "parent", actionData.parentBean.getObj());
if (actionData.nestedComponent instanceof LifeCycle) {
((LifeCycle) actionData.nestedComponent).start();
Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/FixedWindowRollingPolicy.java
==============================================================================
--- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/FixedWindowRollingPolicy.java (original)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/FixedWindowRollingPolicy.java Tue Oct 31 21:42:25 2006
@@ -1,5 +1,5 @@
/**
- * LOGBack: the reliable, fast and flexible logging library for Java.
+ * Logback: the reliable, generic, fast and flexible logging framework.
*
* Copyright (C) 1999-2006, QOS.ch
*
@@ -82,7 +82,8 @@
addWarn(SEE_FNP_NOT_SET);
throw new IllegalStateException(FNP_NOT_SET + SEE_FNP_NOT_SET);
}
- if (activeFileName == null) {
+ // if (activeFileName == null) {
+ if (getActiveFileName() == null) {
addWarn("The ActiveFile name option must be set before using this rolling policy.");
throw new IllegalStateException("The ActiveFileName option must be set.");
}
@@ -136,13 +137,13 @@
// move active file name to min
switch (compressionMode) {
case Compress.NONE:
- util.rename(activeFileName, fileNamePattern.convertInt(minIndex));
+ util.rename(getActiveFileName(), fileNamePattern.convertInt(minIndex));
break;
case Compress.GZ:
- compress.GZCompress(activeFileName, fileNamePattern.convertInt(minIndex));
+ compress.GZCompress(getActiveFileName(), fileNamePattern.convertInt(minIndex));
break;
case Compress.ZIP:
- compress.ZIPCompress(activeFileName, fileNamePattern.convertInt(minIndex));
+ compress.ZIPCompress(getActiveFileName(), fileNamePattern.convertInt(minIndex));
break;
}
}
@@ -154,8 +155,7 @@
* @see {@link setActiveFileName}.
*/
public String getActiveFileName() {
- // TODO This is clearly bogus.
- return activeFileName;
+ return getParentFileName();
}
public int getMaxIndex() {
@@ -173,5 +173,4 @@
public void setMinIndex(int minIndex) {
this.minIndex = minIndex;
}
-
}
Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/RollingFileAppender.java
==============================================================================
--- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/RollingFileAppender.java (original)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/RollingFileAppender.java Tue Oct 31 21:42:25 2006
@@ -79,16 +79,23 @@
}
if (rollingPolicy != null) {
- String afn = rollingPolicy.getActiveFileName();
+ //rollingPolicy.setParent(this);
+ //String afn = rollingPolicy.getActiveFileName();
// the activeFile variable is used by the triggeringPolicy.isTriggeringEvent method
- activeFileCache = new File(afn);
- addInfo("Active log file name: "+afn);
+
+// if (getFile() == null) {
+// setFile(rollingPolicy.getActiveFileName());
+// }
+
+ activeFileCache = new File(getFile());
+ addInfo("Active log file name: "+ getFile());
// The local setFile throws an exception, so we use the parent's version.
// This is to prevent the user from configuring both the RollingFileAppender with
// an activeFileName _and_ the FileAppender's file attribute, causing confusion
// on the attributes' uses.
- super.setFile(afn);
+
+ //super.setFile(rollingPolicy.getActiveFileName());
super.start();
} else {
addWarn("No RollingPolicy was set for the RollingFileAppender named "+ getName());
@@ -131,7 +138,8 @@
}
// Although not certain, the active file name may change after roll over.
- fileName = rollingPolicy.getActiveFileName();
+ //fileName = rollingPolicy.getActiveFileName();
+ fileName = getFile();
addInfo("Active file name is now ["+ fileName+"].");
// the activeFile variable is used by the triggeringPolicy.isTriggeringEvent method
@@ -190,9 +198,9 @@
}
}
- @Override
- public void setFile(String filename) {
- throw new UnsupportedOperationException("With RollingFileAppender please use activeFileName " +
- "option instead of File");
- }
+// @Override
+// public void setFile(String filename) {
+// throw new UnsupportedOperationException("With RollingFileAppender please use activeFileName " +
+// "option instead of File");
+// }
}
Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/RollingPolicy.java
==============================================================================
--- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/RollingPolicy.java (original)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/RollingPolicy.java Tue Oct 31 21:42:25 2006
@@ -1,5 +1,5 @@
/**
- * LOGBack: the reliable, fast and flexible logging library for Java.
+ * Logback: the reliable, generic, fast and flexible logging framework.
*
* Copyright (C) 1999-2006, QOS.ch
*
@@ -9,6 +9,7 @@
*/
package ch.qos.logback.core.rolling;
+import ch.qos.logback.core.FileAppender;
import ch.qos.logback.core.spi.LifeCycle;
@@ -38,4 +39,6 @@
* Get the new name of the active log file.
* */
public String getActiveFileName();
+
+ public void setParent(FileAppender appender);
}
Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/RollingPolicyBase.java
==============================================================================
--- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/RollingPolicyBase.java (original)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/RollingPolicyBase.java Tue Oct 31 21:42:25 2006
@@ -1,5 +1,5 @@
/**
- * LOGBack: the reliable, fast and flexible logging library for Java.
+ * Logback: the reliable, generic, fast and flexible logging framework.
*
* Copyright (C) 1999-2006, QOS.ch
*
@@ -9,6 +9,7 @@
*/
package ch.qos.logback.core.rolling;
+import ch.qos.logback.core.FileAppender;
import ch.qos.logback.core.rolling.helper.Compress;
import ch.qos.logback.core.rolling.helper.FileNamePattern;
import ch.qos.logback.core.spi.ContextAwareBase;
@@ -31,8 +32,9 @@
* FileAppender. Unfortunately, a child component must be self contained
* as it is started before its parent.
*/
- protected String activeFileName = null;
-
+ //protected String activeFileName = null;
+ private FileAppender parent;
+
private boolean started;
/**
@@ -62,15 +64,6 @@
public String getFileNamePattern() {
return fileNamePatternStr;
}
-
- /**
- * ActiveFileName can be left unset, i.e. as null.
- * @see #getActiveFileName
- */
- public void setActiveFileName(String afn) {
- activeFileName = afn;
- }
-
public boolean isStarted() {
return started;
@@ -83,9 +76,14 @@
public void stop() {
started = false;
}
+
+ public void setParent(FileAppender appender) {
+ addInfo("Adding parent to RollingPolicy: " + appender.getName());
+ this.parent = appender;
+ }
- public String getActiveFileName() {
- return activeFileName;
+ public String getParentFileName() {
+ return parent.getFile();
}
}
Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/TimeBasedRollingPolicy.java
==============================================================================
--- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/TimeBasedRollingPolicy.java (original)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/TimeBasedRollingPolicy.java Tue Oct 31 21:42:25 2006
@@ -1,5 +1,5 @@
/**
- * LOGBack: the reliable, fast and flexible logging library for Java.
+ * Logback: the reliable, generic, fast and flexible logging framework.
*
* Copyright (C) 1999-2006, QOS.ch
*
@@ -216,7 +216,7 @@
//addInfo("roll-over called");
//addInfo("compressionMode: " + compressionMode);
- if (activeFileName == null) {
+ if (getParentFileName() == null) {
switch (compressionMode) {
case Compress.NONE:
// nothing to do;
@@ -233,15 +233,15 @@
} else {
switch (compressionMode) {
case Compress.NONE:
- util.rename(activeFileName, elapsedPeriodsFileName);
+ util.rename(getParentFileName(), elapsedPeriodsFileName);
break;
case Compress.GZ:
addInfo("GZIP compressing ["+elapsedPeriodsFileName+"]");
- compress.GZCompress(activeFileName, elapsedPeriodsFileName);
+ compress.GZCompress(getParentFileName(), elapsedPeriodsFileName);
break;
case Compress.ZIP:
addInfo("ZIP compressing ["+elapsedPeriodsFileName+"]");
- compress.ZIPCompress(activeFileName, elapsedPeriodsFileName);
+ compress.ZIPCompress(getParentFileName(), elapsedPeriodsFileName);
break;
}
}
@@ -255,12 +255,11 @@
* as computed by the <b>FileNamePattern</b> option.
*
*/
- @Override
public String getActiveFileName() {
- if (activeFileName == null) {
+ if (getParentFileName() == null) {
return activeFileNamePattern.convertDate(lastCheck);
} else {
- return activeFileName;
+ return getParentFileName();
}
}
@@ -289,5 +288,5 @@
} else {
return false;
}
- }
+ }
}
Modified: logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/RenamingTest.java
==============================================================================
--- logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/RenamingTest.java (original)
+++ logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/RenamingTest.java Tue Oct 31 21:42:25 2006
@@ -22,20 +22,19 @@
import ch.qos.logback.core.util.Compare;
import ch.qos.logback.core.util.StatusPrinter;
-
/**
*
* This test case aims to unit test/reproduce problems encountered while
* renaming the log file under windows.
*
* @author Ceki
- *
+ *
*/
public class RenamingTest extends TestCase {
-
+
Layout layout;
Context context = new ContextBase();
-
+
public RenamingTest(String arg0) {
super(arg0);
}
@@ -43,10 +42,10 @@
protected void setUp() throws Exception {
super.setUp();
layout = new EchoLayout();
-
- File target = new File("src/test/output/test.log");
- target.mkdirs();
- target.delete();
+
+ File target = new File("src/test/output/test.log");
+ target.mkdirs();
+ target.delete();
}
protected void tearDown() throws Exception {
@@ -54,11 +53,11 @@
}
public void testRename() throws Exception {
-
-
+
RollingFileAppender rfa = new RollingFileAppender();
rfa.setLayout(layout);
rfa.setContext(context);
+ rfa.setFile("src/test/output/test.log");
// rollover by the second
String datePattern = "yyyy-MM-dd_HH_mm_ss";
@@ -67,10 +66,11 @@
TimeBasedRollingPolicy tbrp = new TimeBasedRollingPolicy();
tbrp.setFileNamePattern("src/test/output/test-%d{" + datePattern + "}");
- tbrp.setActiveFileName("src/test/output/test.log");
+ //tbrp.setActiveFileName("src/test/output/test.log");
tbrp.setContext(context);
+ tbrp.setParent(rfa);
tbrp.start();
-
+
rfa.setRollingPolicy(tbrp);
rfa.start();
@@ -80,14 +80,15 @@
rfa.doAppend("Hello 0");
Thread.sleep(5000);
rfa.doAppend("Hello 1");
-
+
filenames[0] = "src/test/output/test-" + sdf.format(cal.getTime());
filenames[1] = "src/test/output/test.log";
for (int i = 0; i < filenames.length; i++) {
- System.out.println("before i="+i);
- assertTrue(Compare.compare(filenames[i], "src/test/witness/rolling/renaming." + i));
- System.out.println("post i="+i);
+ System.out.println("before i=" + i);
+ assertTrue(Compare.compare(filenames[i],
+ "src/test/witness/rolling/renaming." + i));
+ System.out.println("post i=" + i);
}
}
}
Modified: logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/SizeBasedRollingTest.java
==============================================================================
--- logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/SizeBasedRollingTest.java (original)
+++ logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/SizeBasedRollingTest.java Tue Oct 31 21:42:25 2006
@@ -74,6 +74,7 @@
FixedWindowRollingPolicy fwrp = new FixedWindowRollingPolicy();
fwrp.setContext(context);
+ fwrp.setParent(rfa);
SizeBasedTriggeringPolicy sbtp = new SizeBasedTriggeringPolicy();
sbtp.setContext(context);
@@ -102,7 +103,9 @@
rfa.setName("ROLLING");
rfa.setLayout(layout);
rfa.setContext(context);
-
+ rfa.setFile(Constants.TEST_DIR_PREFIX
+ + "output/sizeBased-test2.log");
+
FixedWindowRollingPolicy swrp = new FixedWindowRollingPolicy();
swrp.setContext(context);
SizeBasedTriggeringPolicy sbtp = new SizeBasedTriggeringPolicy();
@@ -110,11 +113,12 @@
sbtp.setMaxFileSize("100");
swrp.setMinIndex(0);
- swrp.setActiveFileName(Constants.TEST_DIR_PREFIX
- + "output/sizeBased-test2.log");
+// swrp.setActiveFileName(Constants.TEST_DIR_PREFIX
+// + "output/sizeBased-test2.log");
swrp.setFileNamePattern(Constants.TEST_DIR_PREFIX
+ "output/sizeBased-test2.%i");
+ swrp.setParent(rfa);
swrp.start();
rfa.setRollingPolicy(swrp);
@@ -172,6 +176,7 @@
RollingFileAppender rfa = new RollingFileAppender();
rfa.setLayout(layout);
rfa.setContext(context);
+ rfa.setFile(Constants.TEST_DIR_PREFIX + "output/sbr-test3.log");
FixedWindowRollingPolicy fwrp = new FixedWindowRollingPolicy();
fwrp.setContext(context);
@@ -180,9 +185,10 @@
sbtp.setMaxFileSize("100");
fwrp.setMinIndex(0);
- fwrp.setActiveFileName(Constants.TEST_DIR_PREFIX + "output/sbr-test3.log");
+ //fwrp.setActiveFileName(Constants.TEST_DIR_PREFIX + "output/sbr-test3.log");
fwrp.setFileNamePattern(Constants.TEST_DIR_PREFIX
+ "output/sbr-test3.%i.gz");
+ fwrp.setParent(rfa);
fwrp.start();
rfa.setRollingPolicy(fwrp);
rfa.setTriggeringPolicy(sbtp);
Modified: logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/TimeBasedRollingTest.java
==============================================================================
--- logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/TimeBasedRollingTest.java (original)
+++ logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/TimeBasedRollingTest.java Tue Oct 31 21:42:25 2006
@@ -86,6 +86,7 @@
TimeBasedRollingPolicy tbrp = new TimeBasedRollingPolicy();
tbrp.setFileNamePattern(Constants.TEST_DIR_PREFIX + "output/test1-%d{"
+ DATE_PATTERN + "}");
+ tbrp.setParent(rfa);
tbrp.start();
rfa.setRollingPolicy(tbrp);
rfa.start();
@@ -130,6 +131,7 @@
TimeBasedRollingPolicy tbrp1 = new TimeBasedRollingPolicy();
tbrp1.setFileNamePattern(Constants.TEST_DIR_PREFIX + "output/test2-%d{"
+ DATE_PATTERN + "}");
+ tbrp1.setParent(rfa1);
tbrp1.start();
rfa1.setRollingPolicy(tbrp1);
rfa1.start();
@@ -162,6 +164,7 @@
TimeBasedRollingPolicy tbrp2 = new TimeBasedRollingPolicy();
tbrp2.setFileNamePattern(Constants.TEST_DIR_PREFIX + "output/test2-%d{"
+ DATE_PATTERN + "}");
+ tbrp2.setParent(rfa2);
tbrp2.start();
rfa2.setRollingPolicy(tbrp2);
rfa2.start();
@@ -187,6 +190,7 @@
TimeBasedRollingPolicy tbrp = new TimeBasedRollingPolicy();
tbrp.setFileNamePattern(Constants.TEST_DIR_PREFIX + "output/test3-%d{"
+ DATE_PATTERN + "}.gz");
+ tbrp.setParent(rfa);
tbrp.start();
rfa.setRollingPolicy(tbrp);
rfa.start();
@@ -232,11 +236,13 @@
public void test4() throws Exception {
RollingFileAppender rfa1 = new RollingFileAppender();
rfa1.setLayout(layout);
+ rfa1.setFile(Constants.TEST_DIR_PREFIX + "output/test4.log");
TimeBasedRollingPolicy tbrp1 = new TimeBasedRollingPolicy();
- tbrp1.setActiveFileName(Constants.TEST_DIR_PREFIX + "output/test4.log");
+ //tbrp1.setActiveFileName(Constants.TEST_DIR_PREFIX + "output/test4.log");
tbrp1.setFileNamePattern(Constants.TEST_DIR_PREFIX + "output/test4-%d{"
+ DATE_PATTERN + "}");
+ tbrp1.setParent(rfa1);
tbrp1.start();
rfa1.setRollingPolicy(tbrp1);
rfa1.start();
@@ -266,11 +272,13 @@
RollingFileAppender rfa2 = new RollingFileAppender();
rfa2.setLayout(layout);
+ rfa2.setFile(Constants.TEST_DIR_PREFIX + "output/test4.log");
TimeBasedRollingPolicy tbrp2 = new TimeBasedRollingPolicy();
tbrp2.setFileNamePattern(Constants.TEST_DIR_PREFIX + "output/test4-%d{"
+ DATE_PATTERN + "}");
- tbrp2.setActiveFileName(Constants.TEST_DIR_PREFIX + "output/test4.log");
+ //tbrp2.setActiveFileName(Constants.TEST_DIR_PREFIX + "output/test4.log");
+ tbrp2.setParent(rfa2);
tbrp2.start();
rfa2.setRollingPolicy(tbrp2);
rfa2.start();
@@ -292,11 +300,13 @@
public void test5() throws Exception {
RollingFileAppender rfa = new RollingFileAppender();
rfa.setLayout(layout);
+ rfa.setFile(Constants.TEST_DIR_PREFIX + "output/test5.log");
TimeBasedRollingPolicy tbrp = new TimeBasedRollingPolicy();
tbrp.setFileNamePattern(Constants.TEST_DIR_PREFIX + "output/test5-%d{"
+ DATE_PATTERN + "}");
- tbrp.setActiveFileName(Constants.TEST_DIR_PREFIX + "output/test5.log");
+ //tbrp.setActiveFileName(Constants.TEST_DIR_PREFIX + "output/test5.log");
+ tbrp.setParent(rfa);
tbrp.start();
rfa.setRollingPolicy(tbrp);
rfa.start();
@@ -335,11 +345,13 @@
public void test6() throws Exception {
RollingFileAppender rfa = new RollingFileAppender();
rfa.setLayout(layout);
+ rfa.setFile(Constants.TEST_DIR_PREFIX + "output/test6.log");
TimeBasedRollingPolicy tbrp = new TimeBasedRollingPolicy();
tbrp.setFileNamePattern(Constants.TEST_DIR_PREFIX + "output/test6-%d{"
+ DATE_PATTERN + "}.gz");
- tbrp.setActiveFileName(Constants.TEST_DIR_PREFIX + "output/test6.log");
+ //tbrp.setActiveFileName(Constants.TEST_DIR_PREFIX + "output/test6.log");
+ tbrp.setParent(rfa);
tbrp.start();
rfa.setRollingPolicy(tbrp);
rfa.start();
More information about the logback-dev
mailing list