From 1c749f734d577dddd3669447132460eb70d08e97 Mon Sep 17 00:00:00 2001 From: xuwenping Date: Fri, 19 Jan 2024 21:52:36 +0800 Subject: [PATCH] fix unit test failed Signed-off-by: xuwenping --- .../ch/qos/logback/access/pattern/DateConverter.java | 11 +++++++++-- .../ch/qos/logback/access/pattern/ConverterTest.java | 2 +- .../TimeBasedRollingWithArchiveRemoval_Test.java | 2 +- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/logback-access/src/main/java/ch/qos/logback/access/pattern/DateConverter.java b/logback-access/src/main/java/ch/qos/logback/access/pattern/DateConverter.java index 158619f74d..754a9cdd7d 100644 --- a/logback-access/src/main/java/ch/qos/logback/access/pattern/DateConverter.java +++ b/logback-access/src/main/java/ch/qos/logback/access/pattern/DateConverter.java @@ -15,6 +15,7 @@ import java.time.ZoneId; import java.util.List; +import java.util.Locale; import ch.qos.logback.access.spi.IAccessEvent; import ch.qos.logback.core.CoreConstants; @@ -44,13 +45,19 @@ public void start() { zoneId = ZoneId.of(zoneIdString); } + Locale locale = null; + if (optionList != null && optionList.size() > 2) { + String localeIdStr = optionList.get(2); + locale = Locale.forLanguageTag(localeIdStr); + } + try { - cachingDateFormatter = new CachingDateFormatter(datePattern, zoneId); + cachingDateFormatter = new CachingDateFormatter(datePattern, zoneId, locale); // maximumCacheValidity = CachedDateFormat.getMaximumCacheValidity(pattern); } catch (IllegalArgumentException e) { addWarn("Could not instantiate SimpleDateFormat with pattern " + datePattern, e); addWarn("Defaulting to " + CoreConstants.CLF_DATE_PATTERN); - cachingDateFormatter = new CachingDateFormatter(CoreConstants.CLF_DATE_PATTERN, zoneId); + cachingDateFormatter = new CachingDateFormatter(CoreConstants.CLF_DATE_PATTERN, zoneId, locale); } } diff --git a/logback-access/src/test/java/ch/qos/logback/access/pattern/ConverterTest.java b/logback-access/src/test/java/ch/qos/logback/access/pattern/ConverterTest.java index 07a4875f73..c5de1214d7 100644 --- a/logback-access/src/test/java/ch/qos/logback/access/pattern/ConverterTest.java +++ b/logback-access/src/test/java/ch/qos/logback/access/pattern/ConverterTest.java @@ -76,7 +76,7 @@ public void testDateConverter() { @Test public void testDateConverter_AU_locale() { DateConverter converter = new DateConverter(); - List optionsList = Lists.list(CoreConstants.CLF_DATE_PATTERN, "Australia/Sydney", "en-AU"); + List optionsList = Lists.list(CoreConstants.CLF_DATE_PATTERN, "Australia/Sydney", "en_AU"); converter.setOptionList(optionsList); converter.start(); diff --git a/logback-core/src/test/java/ch/qos/logback/core/rolling/TimeBasedRollingWithArchiveRemoval_Test.java b/logback-core/src/test/java/ch/qos/logback/core/rolling/TimeBasedRollingWithArchiveRemoval_Test.java index 00a1199190..a049a6f90d 100755 --- a/logback-core/src/test/java/ch/qos/logback/core/rolling/TimeBasedRollingWithArchiveRemoval_Test.java +++ b/logback-core/src/test/java/ch/qos/logback/core/rolling/TimeBasedRollingWithArchiveRemoval_Test.java @@ -291,7 +291,7 @@ public void dailySizeBasedRolloverWithSizeCap() { // 2016-03-05 00:14:39 CET long simulatedTime = 1457133279186L; ConfigParameters params = new ConfigParameters(simulatedTime); - String fileNamePattern = randomOutputDir + "/%d{" + DAILY_DATE_PATTERN + "}-clean.%i"; + String fileNamePattern = randomOutputDir + "/%d{" + DAILY_DATE_PATTERN + ", CET}-clean.%i"; params.maxHistory(60).fileNamePattern(fileNamePattern).simulatedNumberOfPeriods(10).sizeCap(sizeCap); logOverMultiplePeriods(params);