Skip to content

Commit

Permalink
rename FileNamePattern.toRegex(Date date) as toRegexForFixedDate(Date…
Browse files Browse the repository at this point in the history
… date)
  • Loading branch information
ceki committed Mar 27, 2013
1 parent b4e996d commit bd4e72c
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 7 deletions.
2 changes: 1 addition & 1 deletion logback-core/src/main/java/ch/qos/logback/core/rolling/SizeAndTimeBasedFNATP.java 100644 → 100755
Expand Up @@ -42,7 +42,7 @@ public void start() {
// we need to get the correct value of currentPeriodsCounter.
// usually the value is 0, unless the appender or the application
// is stopped and restarted within the same period
String regex = tbrp.fileNamePattern.toRegex(dateInCurrentPeriod);
String regex = tbrp.fileNamePattern.toRegexForFixedDate(dateInCurrentPeriod);
String stemRegex = FileFilterUtil.afterLastSlash(regex);


Expand Down
5 changes: 4 additions & 1 deletion logback-core/src/main/java/ch/qos/logback/core/rolling/helper/FileNamePattern.java 100644 → 100755
Expand Up @@ -157,8 +157,11 @@ public String getPattern() {

/**
* Given date, convert this instance to a regular expression.
*
* Used to compute sub-regex when the pattern has both %d and %i, and the
* date is known.
*/
public String toRegex(Date date) {
public String toRegexForFixedDate(Date date) {
StringBuilder buf = new StringBuilder();
Converter<Object> p = headTokenConverter;
while (p != null) {
Expand Down
Expand Up @@ -26,7 +26,7 @@ public SizeAndTimeBasedArchiveRemover(FileNamePattern fileNamePattern,
public void cleanByPeriodOffset(Date now, int periodOffset) {
Date dateOfPeriodToClean = rc.getRelativeDate(now, periodOffset);

String regex = fileNamePattern.toRegex(dateOfPeriodToClean);
String regex = fileNamePattern.toRegexForFixedDate(dateOfPeriodToClean);
String stemRegex = FileFilterUtil.afterLastSlash(regex);
File archive0 = new File(fileNamePattern.convertMultipleArguments(
dateOfPeriodToClean, 0));
Expand Down
2 changes: 1 addition & 1 deletion logback-core/src/test/java/ch/qos/logback/core/helpers/FileFilterUtilTest.java 100644 → 100755
Expand Up @@ -48,7 +48,7 @@ public void findHighestCounterTest() throws ParseException {
FileNamePattern fnp = new FileNamePattern("c:/log/debug-old-%d{yyyy-MM-dd}.%i.log", context);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
String rexexp = null;
rexexp = fnp.toRegex(sdf.parse("2010-08-10"));
rexexp = fnp.toRegexForFixedDate(sdf.parse("2010-08-10"));
String stemRegex = FileFilterUtil.afterLastSlash(rexexp);
int result = FileFilterUtil.findHighestCounter(matchingFileArray, stemRegex);
assertEquals(12, result);
Expand Down
5 changes: 2 additions & 3 deletions logback-core/src/test/java/ch/qos/logback/core/rolling/helper/FileNamePatternTest.java 100644 → 100755
Expand Up @@ -17,7 +17,6 @@

import java.util.Calendar;

import ch.qos.logback.core.util.StatusPrinter;
import org.junit.Test;

import ch.qos.logback.core.Context;
Expand Down Expand Up @@ -114,13 +113,13 @@ public void asRegexByDate() {
{
FileNamePattern fnp = new FileNamePattern("foo-%d{yyyy.MM.dd}-%i.txt",
context);
String regex = fnp.toRegex(cal.getTime());
String regex = fnp.toRegexForFixedDate(cal.getTime());
assertEquals("foo-2003.05.20-(\\d{1,3}).txt", regex);
}
{
FileNamePattern fnp = new FileNamePattern("\\toto\\foo-%d{yyyy\\MM\\dd}-%i.txt",
context);
String regex = fnp.toRegex(cal.getTime());
String regex = fnp.toRegexForFixedDate(cal.getTime());
assertEquals("/toto/foo-2003/05/20-(\\d{1,3}).txt", regex);
}
}
Expand Down

0 comments on commit bd4e72c

Please sign in to comment.