This is an automated email from the ASF dual-hosted git repository.
ckozak pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git
The following commit(s) were added to refs/heads/master by this push:
new 34ab05d LOG4J2-2748: Implement ISO8601_PERIOD_MICROS fixed date format
34ab05d is described below
commit 34ab05dd21ae1d1f85a2a0f658799a18871067d3
Author: Carter Kozak <[email protected]>
AuthorDate: Tue Dec 24 17:24:49 2019 -0500
LOG4J2-2748: Implement ISO8601_PERIOD_MICROS fixed date format
This fixed date format matches ISO8601_PERIOD but adds support for
microsecond precision.
---
.../log4j/core/time/internal/format/FixedDateFormat.java | 7 ++++++-
.../log4j/core/pattern/DatePatternConverterTest.java | 16 ++++++++++++++++
src/changes/changes.xml | 3 +++
3 files changed, 25 insertions(+), 1 deletion(-)
diff --git
a/log4j-core/src/main/java/org/apache/logging/log4j/core/time/internal/format/FixedDateFormat.java
b/log4j-core/src/main/java/org/apache/logging/log4j/core/time/internal/format/FixedDateFormat.java
index 243d0b1..e169ffc 100644
---
a/log4j-core/src/main/java/org/apache/logging/log4j/core/time/internal/format/FixedDateFormat.java
+++
b/log4j-core/src/main/java/org/apache/logging/log4j/core/time/internal/format/FixedDateFormat.java
@@ -136,7 +136,12 @@ public class FixedDateFormat {
/**
* ISO8601 time format: {@code "yyyy-MM-dd'T'HH:mm:ss.SSS"}.
*/
- ISO8601_PERIOD("yyyy-MM-dd'T'HH:mm:ss.SSS", "yyyy-MM-dd'T'", 2, ':',
1, '.', 1, 3, null);
+ ISO8601_PERIOD("yyyy-MM-dd'T'HH:mm:ss.SSS", "yyyy-MM-dd'T'", 2, ':',
1, '.', 1, 3, null),
+
+ /**
+ * ISO8601 time format with support for microsecond precision: {@code
"yyyy-MM-dd'T'HH:mm:ss.nnnnnn"}.
+ */
+ ISO8601_PERIOD_MICROS("yyyy-MM-dd'T'HH:mm:ss.nnnnnn", "yyyy-MM-dd'T'",
2, ':', 1, '.', 1, 6, null);
private static final String DEFAULT_SECOND_FRACTION_PATTERN = "SSS";
private static final int MILLI_FRACTION_DIGITS =
DEFAULT_SECOND_FRACTION_PATTERN.length();
diff --git
a/log4j-core/src/test/java/org/apache/logging/log4j/core/pattern/DatePatternConverterTest.java
b/log4j-core/src/test/java/org/apache/logging/log4j/core/pattern/DatePatternConverterTest.java
index b8e0469..360db1b 100644
---
a/log4j-core/src/test/java/org/apache/logging/log4j/core/pattern/DatePatternConverterTest.java
+++
b/log4j-core/src/test/java/org/apache/logging/log4j/core/pattern/DatePatternConverterTest.java
@@ -163,6 +163,22 @@ public class DatePatternConverterTest {
}
@Test
+ public void testFormatDateStringBuilderIso8601WithPeriodMicroseconds() {
+ final String[] pattern =
{FixedDateFormat.FixedFormat.ISO8601_PERIOD_MICROS.name(), "Z"};
+ final DatePatternConverter converter =
DatePatternConverter.newInstance(pattern);
+ final StringBuilder sb = new StringBuilder();
+ MutableInstant instant = new MutableInstant();
+ instant.initFromEpochMilli(
+ 1577225134559L,
+ // One microsecond
+ 1000);
+ converter.format(instant, sb);
+
+ final String expected = "2019-12-24T22:05:34.559001";
+ assertEquals(expected, sb.toString());
+ }
+
+ @Test
public void testFormatDateStringBuilderOriginalPattern() {
final String[] pattern = {"yyyy/MM/dd HH-mm-ss.SSS"};
final DatePatternConverter converter =
DatePatternConverter.newInstance(pattern);
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 44b0f23..aa6d295 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -184,6 +184,9 @@
<action issue="LOG4J2-2739" dev="ckozak" type="fix">
Fix erroneous log4j-jul recursive logger detection resulting in some
no-op JUL loggers and 'WARN Recursive call to getLogger' being reported by the
status logger.
</action>
+ <action issue="LOG4J2-2748" dev="ckozak" type="add">
+ Implement ISO8601_PERIOD_MICROS fixed date format matching
ISO8601_PERIOD with support for microsecond precision.
+ </action>
</release>
<release version="2.13.0" date="2019-12-11" description="GA Release
2.13.0">
<action issue="LOG4J2-2058" dev="rgoers" type="fix">