[logback-dev] svn commit: r2405 - in logback/trunk: logback-classic/src/test/input/joran/rolling logback-classic/src/test/java/ch/qos/logback/classic/rolling logback-core/src/main/java/ch/qos/logback/core/rolling logback-core/src/main/java/ch/qos/logback/core/rolling/helper logback-core/src/test/java/ch/qos/logback/core/rolling logback-core/src/test/java/ch/qos/logback/core/rolling/helper
noreply.ceki at qos.ch
noreply.ceki at qos.ch
Mon Aug 3 15:23:38 CEST 2009
Author: ceki
Date: Mon Aug 3 15:23:38 2009
New Revision: 2405
Added:
logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/SizeAndTimeBasedFNATP.java
- copied, changed from r2404, /logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/SizeAndTimeBasedFileNamingAndTriggeringPolicy.java
logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/DatePatternToRegex.java
logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/SDFToken.java
logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/SizeAndTimeBasedFNATP_Test.java
- copied, changed from r2404, /logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/SizeAndTimeBasedFileNamingAndTriggeringPolicyTest.java
Removed:
logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/SizeAndTimeBasedFileNamingAndTriggeringPolicy.java
logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/SizeAndTimeBasedFileNamingAndTriggeringPolicyTest.java
Modified:
logback/trunk/logback-classic/src/test/input/joran/rolling/timeAndSize.xml
logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/rolling/TimeBasedRollingWithConfigFileTest.java
logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/DateTokenConverter.java
logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/FileNamePattern.java
logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/PackageTest.java
logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/ScaffoldingForRollingTests.java
logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/helper/FileNamePatternTest.java
Log:
ongoing work
Modified: logback/trunk/logback-classic/src/test/input/joran/rolling/timeAndSize.xml
==============================================================================
--- logback/trunk/logback-classic/src/test/input/joran/rolling/timeAndSize.xml (original)
+++ logback/trunk/logback-classic/src/test/input/joran/rolling/timeAndSize.xml Mon Aug 3 15:23:38 2009
@@ -9,7 +9,7 @@
${randomOutputDir}${testId}-%d{yyyy-MM-dd_HH_mm_ss}.%i
</FileNamePattern>
<TimeBasedFileNamingAndTriggeringPolicy
- class="ch.qos.logback.core.rolling.SizeAndTimeBasedFileNamingAndTriggeringPolicy">
+ class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<MaxFileSize>${sizeThreshold}</MaxFileSize>
</TimeBasedFileNamingAndTriggeringPolicy>
</rollingPolicy>
Modified: logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/rolling/TimeBasedRollingWithConfigFileTest.java
==============================================================================
--- logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/rolling/TimeBasedRollingWithConfigFileTest.java (original)
+++ logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/rolling/TimeBasedRollingWithConfigFileTest.java Mon Aug 3 15:23:38 2009
@@ -1,3 +1,12 @@
+/**
+ * Logback: the generic, reliable, fast and flexible logging framework.
+ *
+ * Copyright (C) 2000-2009, QOS.ch
+ *
+ * This library is free software, you can redistribute it and/or modify it under
+ * the terms of the GNU Lesser General Public License as published by the Free
+ * Software Foundation.
+ */
package ch.qos.logback.classic.rolling;
import static org.junit.Assert.assertTrue;
@@ -28,7 +37,7 @@
int fileSize = 0;
int fileIndexCounter = -1;
int sizeThreshold;
-
+
@Before
@Override
public void setUp() {
@@ -53,23 +62,23 @@
public void basic() throws Exception {
String testId = "basic";
lc.putProperty("testId", testId);
- loadConfig(ClassicTestConstants.JORAN_INPUT_PREFIX + "/rolling/"+testId+".xml");
+ loadConfig(ClassicTestConstants.JORAN_INPUT_PREFIX + "/rolling/" + testId
+ + ".xml");
StatusChecker sc = new StatusChecker(lc);
assertTrue(sc.isErrorFree());
-
+
Logger root = lc.getLogger(Logger.ROOT_LOGGER_NAME);
-
- expectedFilenameList.add(randomOutputDir+"z"+testId);
-
+
+ expectedFilenameList.add(randomOutputDir + "z" + testId);
+
RollingFileAppender<ILoggingEvent> rfa = (RollingFileAppender<ILoggingEvent>) root
.getAppender("ROLLING");
TimeBasedRollingPolicy tprp = (TimeBasedRollingPolicy<ILoggingEvent>) rfa
.getTriggeringPolicy();
- TimeBasedFileNamingAndTriggeringPolicy tbnatp = tprp.getTimeBasedFileNamingAndTriggeringPolicy();
-
+ TimeBasedFileNamingAndTriggeringPolicy tbnatp = tprp
+ .getTimeBasedFileNamingAndTriggeringPolicy();
-
String prefix = "Hello---";
int runLength = 4;
for (int i = 0; i < runLength; i++) {
@@ -80,38 +89,39 @@
}
existenceCheck(expectedFilenameList);
- sortedContentCheck(randomOutputDir, runLength, prefix);
+ sortedContentCheck(randomOutputDir, runLength, prefix);
}
-
+
@Test
public void timeAndSize() throws Exception {
String testId = "timeAndSize";
lc.putProperty("testId", testId);
String prefix = "Hello-----";
- int hits = 64;
- sizeThreshold = prefix.length()*hits;
- lc.putProperty("sizeThreshold", ""+sizeThreshold);
- loadConfig(ClassicTestConstants.JORAN_INPUT_PREFIX + "/rolling/"+testId+".xml");
+
+ // the number of times the log file will be written to before time based
+ // roll-over occurs
+ int approxWritesPerPeriod = 64;
+ sizeThreshold = prefix.length() * approxWritesPerPeriod;
+ lc.putProperty("sizeThreshold", "" + sizeThreshold);
+ loadConfig(ClassicTestConstants.JORAN_INPUT_PREFIX + "/rolling/" + testId
+ + ".xml");
Logger root = lc.getLogger(Logger.ROOT_LOGGER_NAME);
-
- expectedFilenameList.add(randomOutputDir+"z"+testId);
-
+ expectedFilenameList.add(randomOutputDir + "z" + testId);
+
RollingFileAppender<ILoggingEvent> rfa = (RollingFileAppender<ILoggingEvent>) root
.getAppender("ROLLING");
StatusChecker sc = new StatusChecker(lc);
assertTrue(sc.isErrorFree());
-
TimeBasedRollingPolicy tprp = (TimeBasedRollingPolicy<ILoggingEvent>) rfa
.getTriggeringPolicy();
- TimeBasedFileNamingAndTriggeringPolicy tbnatp = tprp.getTimeBasedFileNamingAndTriggeringPolicy();
-
+ TimeBasedFileNamingAndTriggeringPolicy tbnatp = tprp
+ .getTimeBasedFileNamingAndTriggeringPolicy();
-
- int timeIncrement = 1000/hits;
- int runLength = (1000/timeIncrement)*3;
+ int timeIncrement = 1000 / approxWritesPerPeriod;
+ int runLength = approxWritesPerPeriod * 3;
for (int i = 0; i < runLength; i++) {
String msg = prefix + i;
logger.debug(msg);
@@ -120,12 +130,16 @@
tbnatp.setCurrentTime(currentTime);
}
- sortedContentCheck(randomOutputDir, runLength, prefix);
+ sortedContentCheck(randomOutputDir, runLength, prefix);
int eCount = existenceCount(expectedFilenameList);
- assertTrue("eCount="+eCount+"expectedFilenameList.size="+expectedFilenameList.size(), eCount >= 5 && eCount > expectedFilenameList.size()/2);
+ // for various reasons, it is extremely difficult to have the files
+ // match exactly the expected archive files. Thus, we aim for
+ // an approximate match
+ assertTrue("eCount=" + eCount + "expectedFilenameList.size="
+ + expectedFilenameList.size(), eCount >= 5
+ && eCount > expectedFilenameList.size() / 2);
}
-
-
+
void addExpectedFileNamedIfItsTime(String testId, String msg,
boolean gzExtension) {
fileSize += msg.getBytes().length;
@@ -154,15 +168,16 @@
String fn = randomOutputDir + testId + "-" + SDF.format(date) + "."
+ fileIndexCounter;
- System.out.println("Adding "+fn);
+ System.out.println("Adding " + fn);
if (gzExtension) {
fn += ".gz";
}
expectedFilenameList.add(fn);
}
-
+
@Override
- protected void addExpectedFileNamedIfItsTime_ByDate(String testId, boolean gzExtension) {
+ protected void addExpectedFileNamedIfItsTime_ByDate(String testId,
+ boolean gzExtension) {
if (passThresholdTime(nextRolloverThreshold)) {
addExpectedFileName_ByDate(testId, getDateOfPreviousPeriodsStart(),
gzExtension);
Copied: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/SizeAndTimeBasedFNATP.java (from r2404, /logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/SizeAndTimeBasedFileNamingAndTriggeringPolicy.java)
==============================================================================
--- /logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/SizeAndTimeBasedFileNamingAndTriggeringPolicy.java (original)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/SizeAndTimeBasedFNATP.java Mon Aug 3 15:23:38 2009
@@ -16,7 +16,7 @@
import ch.qos.logback.core.util.FileSize;
@NoAutoStart
-public class SizeAndTimeBasedFileNamingAndTriggeringPolicy<E> extends
+public class SizeAndTimeBasedFNATP<E> extends
TimeBasedFileNamingAndTriggeringPolicyBase<E> {
int currentPeriodsCounter = 0;
Added: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/DatePatternToRegex.java
==============================================================================
--- (empty file)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/DatePatternToRegex.java Mon Aug 3 15:23:38 2009
@@ -0,0 +1,47 @@
+package ch.qos.logback.core.rolling.helper;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class DatePatternToRegex {
+
+ final String datePattern;
+ final int length;
+
+ DatePatternToRegex(String datePattern) {
+ this.datePattern = datePattern;
+ length = datePattern.length();
+ }
+
+ public String toRegex(String datePattern) {
+ List<SDFToken> tokenList = tokenize();
+ for(SDFToken token: tokenList) {
+
+ }
+ char c = 0;
+ for (int i = 0; i < length; i++) {
+ char t = 1;
+ }
+ return null;
+ }
+
+ List<SDFToken> tokenize() {
+ List<SDFToken> tokenList = new ArrayList<SDFToken>();
+ SDFToken token = null;
+ for (int i = 0; i < length; i++) {
+ char t = datePattern.charAt(i);
+ if (token == null || token.c != t) {
+ token = addNewToken(tokenList, t);
+ } else {
+ token.inc();
+ }
+ }
+ return tokenList;
+ }
+
+ SDFToken addNewToken(List<SDFToken> tokenList, char t) {
+ SDFToken token = new SDFToken(t);
+ tokenList.add(token);
+ return token;
+ }
+}
Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/DateTokenConverter.java
==============================================================================
--- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/DateTokenConverter.java (original)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/DateTokenConverter.java Mon Aug 3 15:23:38 2009
@@ -66,6 +66,9 @@
return (o instanceof Date);
}
+ String toRegex() {
+ return null;
+ }
/**
* Set the date pattern.
*/
Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/FileNamePattern.java
==============================================================================
--- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/FileNamePattern.java (original)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/FileNamePattern.java Mon Aug 3 15:23:38 2009
@@ -10,12 +10,14 @@
package ch.qos.logback.core.rolling.helper;
+import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import ch.qos.logback.core.Context;
import ch.qos.logback.core.pattern.Converter;
import ch.qos.logback.core.pattern.ConverterUtil;
+import ch.qos.logback.core.pattern.LiteralConverter;
import ch.qos.logback.core.pattern.parser.Node;
import ch.qos.logback.core.pattern.parser.Parser;
import ch.qos.logback.core.pattern.parser.ScanException;
@@ -136,4 +138,22 @@
public String getPattern() {
return pattern;
}
+
+
+ // Given date, convert this instance to a regular expression
+ String asRegex(Date date) {
+ StringBuilder buf = new StringBuilder();
+ Converter<Object> p = headTokenConverter;
+ while (p != null) {
+ if(p instanceof LiteralConverter) {
+ buf.append(p.convert(null));
+ } else if (p instanceof IntegerTokenConverter) {
+ buf.append("\\d{1,2}");
+ } else if(p instanceof DateTokenConverter) {
+ buf.append(p.convert(date));
+ }
+ p = p.getNext();
+ }
+ return buf.toString();
+ }
}
Added: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/SDFToken.java
==============================================================================
--- (empty file)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/SDFToken.java Mon Aug 3 15:23:38 2009
@@ -0,0 +1,18 @@
+/**
+ *
+ */
+package ch.qos.logback.core.rolling.helper;
+
+class SDFToken {
+ final char c;
+ int occurrences;
+
+ public SDFToken(char c) {
+ this.c = c;
+ this.occurrences = 1;
+ }
+
+ void inc() {
+ occurrences++;
+ }
+}
\ No newline at end of file
Modified: logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/PackageTest.java
==============================================================================
--- logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/PackageTest.java (original)
+++ logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/PackageTest.java Mon Aug 3 15:23:38 2009
@@ -7,7 +7,7 @@
@Suite.SuiteClasses( { RenamingTest.class, SizeBasedRollingTest.class,
TimeBasedRollingTest.class, TimeBasedRollingWithCleanTest.class,
MultiThreadedRollingTest.class,
- SizeAndTimeBasedFileNamingAndTriggeringPolicyTest.class,
+ SizeAndTimeBasedFNATP_Test.class,
ch.qos.logback.core.rolling.helper.PackageTest.class })
public class PackageTest {
}
Modified: logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/ScaffoldingForRollingTests.java
==============================================================================
--- logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/ScaffoldingForRollingTests.java (original)
+++ logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/ScaffoldingForRollingTests.java Mon Aug 3 15:23:38 2009
@@ -1,3 +1,12 @@
+/**
+ * Logback: the generic, reliable, fast and flexible logging framework.
+ *
+ * Copyright (C) 2000-2009, QOS.ch
+ *
+ * This library is free software, you can redistribute it and/or modify it under
+ * the terms of the GNU Lesser General Public License as published by the Free
+ * Software Foundation.
+ */
package ch.qos.logback.core.rolling;
import static org.junit.Assert.assertEquals;
Copied: logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/SizeAndTimeBasedFNATP_Test.java (from r2404, /logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/SizeAndTimeBasedFileNamingAndTriggeringPolicyTest.java)
==============================================================================
--- /logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/SizeAndTimeBasedFileNamingAndTriggeringPolicyTest.java (original)
+++ logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/SizeAndTimeBasedFNATP_Test.java Mon Aug 3 15:23:38 2009
@@ -16,10 +16,10 @@
import org.junit.Before;
import org.junit.Test;
-public class SizeAndTimeBasedFileNamingAndTriggeringPolicyTest extends
+public class SizeAndTimeBasedFNATP_Test extends
ScaffoldingForRollingTests {
- SizeAndTimeBasedFileNamingAndTriggeringPolicy<Object> satbfnatPolicy = new SizeAndTimeBasedFileNamingAndTriggeringPolicy<Object>();
+ SizeAndTimeBasedFNATP<Object> sizeAndTimeBasedFNATP = new SizeAndTimeBasedFNATP<Object>();
RollingFileAppender<Object> rfa1 = new RollingFileAppender<Object>();
TimeBasedRollingPolicy<Object> tbrp1 = new TimeBasedRollingPolicy<Object>();
@@ -46,8 +46,8 @@
int sizeThreshold, long givenTime, long lastCheck) {
tbrp.setContext(context);
- satbfnatPolicy.setMaxFileSize("" + sizeThreshold);
- tbrp.setTimeBasedFileNamingAndTriggeringPolicy(satbfnatPolicy);
+ sizeAndTimeBasedFNATP.setMaxFileSize("" + sizeThreshold);
+ tbrp.setTimeBasedFileNamingAndTriggeringPolicy(sizeAndTimeBasedFNATP);
tbrp.setFileNamePattern(filenamePattern);
tbrp.setParent(rfa);
tbrp.timeBasedTriggering.setCurrentTime(givenTime);
Modified: logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/helper/FileNamePatternTest.java
==============================================================================
--- logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/helper/FileNamePatternTest.java (original)
+++ logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/helper/FileNamePatternTest.java Mon Aug 3 15:23:38 2009
@@ -106,4 +106,17 @@
assertEquals("foo-2003.05.20-79.txt", fnp.convertMultipleArguments(cal.getTime(), 79));
}
+ @Test
+ public void asRegexByDate() {
+ Calendar cal = Calendar.getInstance();
+ cal.set(2003, 4, 20, 17, 55);
+
+ FileNamePattern fnp = new FileNamePattern("foo-%d{yyyy.MM.dd}-%i.txt", context);
+
+ String regex = fnp.asRegex(cal.getTime());
+
+ assertEquals("foo-2003.05.20-\\d{1,2}.txt", regex);
+ }
+
+
}
More information about the logback-dev
mailing list