[logback-dev] [GIT] Logback: the generic, reliable, fast and flexible logging framework. branch master updated. v_1.0.0-55-g0fe93ab

ceki ceki at qos.ch
Wed Dec 21 10:44:08 CET 2011


Thanks Joern. Fixed in https://github.com/ceki/logback/commit/a796df50

On 21.12.2011 10:23, Joern Huxhorn wrote:
> ch.qos.logback.core.rolling.helper.FileNamePatternTest.convertMultipleDates is currently failing with the following message:
>
> expected:<foo[]2003.05/2003.05.20.t...>  but was:<foo[-]2003.05/2003.05.20.t...>
>
> Cheers,
> Joern.
>
> On 20.12.2011, at 19:42, Gitbot wrote:
>
>> 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  0fe93ab52a11545a7f88fd367d4777d14c733606 (commit)
>>       from  fef529f87d72e94a582e5cd515c7acaddf01e07e (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=0fe93ab52a11545a7f88fd367d4777d14c733606
>> http://github.com/ceki/logback/commit/0fe93ab52a11545a7f88fd367d4777d14c733606
>>
>> commit 0fe93ab52a11545a7f88fd367d4777d14c733606
>> Author: Ceki Gulcu<ceki at qos.ch>
>> Date:   Tue Dec 20 19:41:28 2011 +0100
>>
>>     Added support for multiple %d tokens in FileNamePattern
>>
>> diff --git a/logback-classic/src/test/resources/TWO_DATE_logback-test.xml b/logback-classic/src/test/resources/TWO_DATE_logback-test.xml
>> new file mode 100644
>> index 0000000..d2c3444
>> --- /dev/null
>> +++ b/logback-classic/src/test/resources/TWO_DATE_logback-test.xml
>> @@ -0,0 +1,21 @@
>> +<configuration>
>> +<statusListener class="ch.qos.logback.core.status.OnConsoleStatusListener"/>
>> +
>> +<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
>> +<file>test.log</file>
>> +
>> +
>> +<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
>> +<!-- rollover every minute -->
>> +<fileNamePattern>bla-%d{yyyy-MM-dd, SECONDARY}/app.%d{yyyy-MM-dd'T'HH_mm}.log</fileNamePattern>
>> +</rollingPolicy>
>> +
>> +<encoder>
>> +<pattern>%d{"yyyy-MM-dd HH:mm:ss,SSS"} [%thread] %-5level %logger{36} - %msg%n%xEx</pattern>
>> +</encoder>
>> +</appender>
>> +
>> +<root level="DEBUG">
>> +<appender-ref ref="FILE"/>
>> +</root>
>> +</configuration>
>> \ No newline at end of file
>> diff --git a/logback-core/src/main/java/ch/qos/logback/core/rolling/TimeBasedFileNamingAndTriggeringPolicyBase.java b/logback-core/src/main/java/ch/qos/logback/core/rolling/TimeBasedFileNamingAndTriggeringPolicyBase.java
>> index b1690ad..b5a05da 100644
>> --- a/logback-core/src/main/java/ch/qos/logback/core/rolling/TimeBasedFileNamingAndTriggeringPolicyBase.java
>> +++ b/logback-core/src/main/java/ch/qos/logback/core/rolling/TimeBasedFileNamingAndTriggeringPolicyBase.java
>> @@ -41,7 +41,7 @@ abstract public class TimeBasedFileNamingAndTriggeringPolicyBase<E>  extends
>>    }
>>
>>    public void start() {
>> -    DateTokenConverter dtc = tbrp.fileNamePattern.getDateTokenConverter();
>> +    DateTokenConverter dtc = tbrp.fileNamePattern.getPrimaryDateTokenConverter();
>>      if (dtc == null) {
>>        throw new IllegalStateException("FileNamePattern ["
>>                + tbrp.fileNamePattern.getPattern()
>> diff --git a/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/DateTokenConverter.java b/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/DateTokenConverter.java
>> index 582336d..5225d56 100644
>> --- a/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/DateTokenConverter.java
>> +++ b/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/DateTokenConverter.java
>> @@ -14,6 +14,7 @@
>> package ch.qos.logback.core.rolling.helper;
>>
>> import java.util.Date;
>> +import java.util.List;
>>
>> import ch.qos.logback.core.CoreConstants;
>> import ch.qos.logback.core.pattern.DynamicConverter;
>> @@ -30,16 +31,27 @@ public class DateTokenConverter<E>  extends DynamicConverter<E>  implements MonoTy
>>     * The conversion word/character with which this converter is registered.
>>     */
>>    public final static String CONVERTER_KEY = "d";
>> +  public final static String SECONDARY_TOKEN = "SECONDARY";
>>    public static final String DEFAULT_DATE_PATTERN = CoreConstants.DAILY_DATE_PATTERN;
>>
>>    private String datePattern;
>>    private CachingDateFormatter cdf;
>> -
>> +  // is this token converter primary or secondary? Only the primary converter
>> +  // determines the rolling period
>> +  private boolean secondary = false;
>>    public void start() {
>>      this.datePattern = getFirstOption();
>>      if (this.datePattern == null) {
>>        this.datePattern = DEFAULT_DATE_PATTERN;
>>      }
>> +
>> +    final List<String>  optionList = getOptionList();
>> +    if(optionList != null&&  optionList.size()>  1) {
>> +      String secondOption = optionList.get(1);
>> +      if(SECONDARY_TOKEN.equalsIgnoreCase(secondOption)) {
>> +        secondary = true;
>> +      }
>> +    }
>>      cdf = new CachingDateFormatter(datePattern);
>>    }
>>
>> @@ -72,4 +84,8 @@ public class DateTokenConverter<E>  extends DynamicConverter<E>  implements MonoTy
>>      DatePatternToRegexUtil toRegex = new DatePatternToRegexUtil(datePattern);
>>      return toRegex.toRegex();
>>    }
>> +
>> +  public boolean isPrimary() {
>> +    return !secondary;
>> +  }
>> }
>> diff --git a/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/DefaultArchiveRemover.java b/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/DefaultArchiveRemover.java
>> index 85b494a..8253844 100644
>> --- a/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/DefaultArchiveRemover.java
>> +++ b/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/DefaultArchiveRemover.java
>> @@ -75,7 +75,7 @@ abstract public class DefaultArchiveRemover extends ContextAwareBase implements
>>    abstract void cleanByPeriodOffset(Date now, int periodOffset);
>>
>>    boolean computeParentCleaningFlag(FileNamePattern fileNamePattern) {
>> -    DateTokenConverter dtc = fileNamePattern.getDateTokenConverter();
>> +    DateTokenConverter dtc = fileNamePattern.getPrimaryDateTokenConverter();
>>      // if the date pattern has a /, then we need parent cleaning
>>      if (dtc.getDatePattern().indexOf('/') != -1) {
>>        return true;
>> diff --git a/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/FileNamePattern.java b/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/FileNamePattern.java
>> index 67f207b..dab1a72 100644
>> --- a/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/FileNamePattern.java
>> +++ b/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/FileNamePattern.java
>> @@ -81,12 +81,15 @@ public class FileNamePattern extends ContextAwareBase {
>>      return pattern;
>>    }
>>
>> -  public DateTokenConverter getDateTokenConverter() {
>> +  public DateTokenConverter getPrimaryDateTokenConverter() {
>>      Converter p = headTokenConverter;
>>
>>      while (p != null) {
>>        if (p instanceof DateTokenConverter) {
>> -        return (DateTokenConverter) p;
>> +        DateTokenConverter dtc = (DateTokenConverter) p;
>> +        // only primary converters should be returned as
>> +        if(dtc.isPrimary())
>> +          return dtc;
>>        }
>>
>>        p = p.getNext();
>> diff --git a/logback-core/src/test/java/ch/qos/logback/core/rolling/TimeBasedFileNamingAndTriggeringPolicyBaseTest.java b/logback-core/src/test/java/ch/qos/logback/core/rolling/TimeBasedFileNamingAndTriggeringPolicyBaseTest.java
>> new file mode 100644
>> index 0000000..7d574a4
>> --- /dev/null
>> +++ b/logback-core/src/test/java/ch/qos/logback/core/rolling/TimeBasedFileNamingAndTriggeringPolicyBaseTest.java
>> @@ -0,0 +1,68 @@
>> +package ch.qos.logback.core.rolling;
>> +
>> +import ch.qos.logback.core.Context;
>> +import ch.qos.logback.core.ContextBase;
>> +import org.junit.Before;
>> +import org.junit.Test;
>> +
>> +import java.util.logging.Logger;
>> +
>> +import static org.junit.Assert.assertEquals;
>> +
>> +/**
>> + * @author Ceki Gücü
>> + */
>> +public class TimeBasedFileNamingAndTriggeringPolicyBaseTest {
>> +
>> +  static long MILLIS_IN_MINUTE = 60*1000;
>> +
>> +  Context context = new ContextBase();
>> +  RollingFileAppender rfa = new RollingFileAppender();
>> +  TimeBasedRollingPolicy tbrp = new TimeBasedRollingPolicy();
>> +  DefaultTimeBasedFileNamingAndTriggeringPolicy timeBasedFNATP = new DefaultTimeBasedFileNamingAndTriggeringPolicy();
>> +
>> +  @Before
>> +  public void setUp() {
>> +    rfa.setContext(context);
>> +    tbrp.setContext(context);
>> +    timeBasedFNATP.setContext(context);
>> +
>> +    rfa.setRollingPolicy(tbrp);
>> +    tbrp.setParent(rfa);
>> +    tbrp.setTimeBasedFileNamingAndTriggeringPolicy(timeBasedFNATP);
>> +    timeBasedFNATP.setTimeBasedRollingPolicy(tbrp);
>> +  }
>> +
>> +  @Test
>> +  public void singleDate() {
>> +    // Tuesday December 20th 17:59:01 CET 2011
>> +    long startTime = 1324400341553L;
>> +    tbrp.setFileNamePattern("foo-%d{yyyy-MM'T'mm}.log");
>> +    tbrp.start();
>> +
>> +    timeBasedFNATP.setCurrentTime(startTime);
>> +    timeBasedFNATP.start();
>> +
>> +    timeBasedFNATP.setCurrentTime(startTime+MILLIS_IN_MINUTE);
>> +    timeBasedFNATP.isTriggeringEvent(null, null);
>> +    String elapsedPeriodsFileName = timeBasedFNATP.getElapsedPeriodsFileName();
>> +    assertEquals("foo-2011-12T59.log", elapsedPeriodsFileName);
>> +  }
>> +
>> + at Test
>> +  public void multiDate() {
>> +    // Tuesday December 20th 17:59:01 CET 2011
>> +    long startTime = 1324400341553L;
>> +    tbrp.setFileNamePattern("foo-%d{yyyy-MM, SECONDARY}/%d{mm}.log");
>> +    tbrp.start();
>> +
>> +    timeBasedFNATP.setCurrentTime(startTime);
>> +    timeBasedFNATP.start();
>> +
>> +    timeBasedFNATP.setCurrentTime(startTime+MILLIS_IN_MINUTE);
>> +    timeBasedFNATP.isTriggeringEvent(null, null);
>> +    String elapsedPeriodsFileName = timeBasedFNATP.getElapsedPeriodsFileName();
>> +    assertEquals("foo-2011-12/59.log", elapsedPeriodsFileName);
>> +  }
>> +
>> +}
>> diff --git a/logback-core/src/test/java/ch/qos/logback/core/rolling/helper/FileNamePatternTest.java b/logback-core/src/test/java/ch/qos/logback/core/rolling/helper/FileNamePatternTest.java
>> index 7f069cf..8a35f15 100644
>> --- a/logback-core/src/test/java/ch/qos/logback/core/rolling/helper/FileNamePatternTest.java
>> +++ b/logback-core/src/test/java/ch/qos/logback/core/rolling/helper/FileNamePatternTest.java
>> @@ -17,6 +17,7 @@ import static org.junit.Assert.assertEquals;
>>
>> import java.util.Calendar;
>>
>> +import ch.qos.logback.core.util.StatusPrinter;
>> import org.junit.Test;
>>
>> import ch.qos.logback.core.Context;
>> @@ -139,4 +140,13 @@ public class FileNamePatternTest {
>>        assertEquals("foo-\\d{4}\\.\\d{2}\\.\\d{2}T-\\d{1,2}.txt", regex);
>>      }
>>    }
>> +
>> +  @Test
>> +  public void convertMultipleDates() {
>> +    Calendar cal = Calendar.getInstance();
>> +    cal.set(2003, 4, 20, 17, 55);
>> +    FileNamePattern fnp = new FileNamePattern("foo-%d{yyyy.MM, SECONDARY}/%d{yyyy.MM.dd}.txt", context);
>> +    assertEquals("foo2003.05/2003.05.20.txt", fnp.convert(cal.getTime()));
>> +
>> +  }
>> }
>>
>> -----------------------------------------------------------------------
>>
>> Summary of changes:
>> .../src/test/resources/TWO_DATE_logback-test.xml   |   21 ++++++
>> ...TimeBasedFileNamingAndTriggeringPolicyBase.java |    2 +-
>> .../core/rolling/helper/DateTokenConverter.java    |   18 +++++-
>> .../core/rolling/helper/DefaultArchiveRemover.java |    2 +-
>> .../core/rolling/helper/FileNamePattern.java       |    7 ++-
>> ...BasedFileNamingAndTriggeringPolicyBaseTest.java |   68 ++++++++++++++++++++
>> .../core/rolling/helper/FileNamePatternTest.java   |   10 +++
>> 7 files changed, 123 insertions(+), 5 deletions(-)
>> create mode 100644 logback-classic/src/test/resources/TWO_DATE_logback-test.xml
>> create mode 100644 logback-core/src/test/java/ch/qos/logback/core/rolling/TimeBasedFileNamingAndTriggeringPolicyBaseTest.java
>>
>>
>> hooks/post-receive
>> --
>> Logback: the generic, reliable, fast and flexible logging framework.
>> _______________________________________________
>> logback-dev mailing list
>> logback-dev at qos.ch
>> http://mailman.qos.ch/mailman/listinfo/logback-dev
>
> _______________________________________________
> logback-dev mailing list
> logback-dev at qos.ch
> http://mailman.qos.ch/mailman/listinfo/logback-dev


-- 
Ceki
http://twitter.com/#!/ceki


More information about the logback-dev mailing list