Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
b552557
Created an enum for choosing a named pattern.
ashr123 Jun 28, 2025
9d330d4
Applied `spotless:apply`
ashr123 Jun 28, 2025
8f427a0
Added changelog entry
ashr123 Jun 28, 2025
b19d830
No need for (another) default hard-coded named pattern
ashr123 Jun 28, 2025
3df9d88
Fixed small bug
ashr123 Jun 28, 2025
1966a31
fixes some of @vy comments
ashr123 Jul 3, 2025
3418e4c
changed enum to `NamedDatePattern`
ashr123 Jul 3, 2025
9758413
now taking all named patterns automatically
ashr123 Jul 4, 2025
0ef914b
Improve style and cross references in docs
vy Jul 8, 2025
1f4916a
Fix XML typo
vy Jul 8, 2025
4ce71a1
Improve changelog description
vy Jul 8, 2025
2c51fdd
introduced a jakarta support range for the bnd tool (#3791)
jcompagner Jun 30, 2025
b1c0f4e
doc: Clarify and enhance `GraalVmProcessor` configuration example (#3…
ppkarwasz Jul 3, 2025
0877515
fix: Fix Java type for annotated array parameters (#3797)
ppkarwasz Jul 3, 2025
46a5fe2
Bump com.fasterxml.jackson:jackson-bom from 2.19.0 to 2.19.1 in /log4…
dependabot[bot] Jul 3, 2025
8afe892
Update `org.junit:junit-bom` to version `5.13.2` (#3782)
dependabot[bot] Jul 3, 2025
7f2fbe3
Update `com.github.luben:zstd-jni` to version `1.5.7-4` (#3799)
dependabot[bot] Jul 3, 2025
8b889ba
fix: Disable sharing of formatted timestamps between threads (#3802)
ppkarwasz Jul 4, 2025
b408f81
fix: Add GraalVM reachability metadata for non-plugin class instantia…
ppkarwasz Jul 4, 2025
ea6deb7
fix: Add `resource:` protocol to allowed URL schemes by default (#3795)
ppkarwasz Jul 4, 2025
d1e3cb5
Bump org.junit:junit-bom from 5.13.2 to 5.13.3 in /log4j-parent (#3806)
dependabot[bot] Jul 7, 2025
94e060d
Apply suggestion from @ppkarwasz
ashr123 Jul 9, 2025
66c8382
implemented @ppkarwasz & @vy chamges regarding `FixedDateFormat.Fixed…
ashr123 Jul 9, 2025
ee48520
Added a JavaDoc for `NamedInstantPattern#getPattern`
Jul 9, 2025
8066ba6
fix: expose legacy `FixedFormat` patterns via `NamedInstantPattern`
ppkarwasz Jul 9, 2025
6c7ed23
fix: precision of `InstantPatternLegacyFormatter`
ppkarwasz Jul 10, 2025
7d77e1f
fix: dynamically compute legacy date format pattern
ppkarwasz Jul 10, 2025
782bfb2
fix: missing Javadoc heading
ppkarwasz Jul 10, 2025
fb29e3c
fix: hardcode legacy patterns
ppkarwasz Jul 13, 2025
952c790
fix: revert fix for #3816
ppkarwasz Jul 13, 2025
cad6534
fix: Do not test precision of NamedInstantPattern
ppkarwasz Jul 13, 2025
7674eea
Correct log message format in `AbstractDriverManagerConnectionSource`…
jhl221123 Jul 20, 2025
16bb60b
Merge release `2.25.1` back into `2.x` (#3820)
ppkarwasz Jul 20, 2025
e0ac7af
fix: Prevent `LogBuilder` memory leak in Log4j API to Logback bridge …
ppkarwasz Jul 20, 2025
407457a
Merge branch '2.x' into feature/2.x/enumerating-and-exposing-named-pa…
vy Jul 20, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ public final class DatePatternConverter extends LogEventPatternConverter impleme

private static final String CLASS_NAME = DatePatternConverter.class.getSimpleName();

private static final String DEFAULT_PATTERN = "yyyy-MM-dd HH:mm:ss,SSS";

private final InstantFormatter formatter;

private DatePatternConverter(@Nullable final String[] options) {
Expand All @@ -64,7 +62,9 @@ private static InstantFormatter createFormatter(@Nullable final String[] options
} catch (final Exception error) {
logOptionReadFailure(options, error, "failed for options: {}, falling back to the default instance");
}
return InstantPatternFormatter.newBuilder().setPattern(DEFAULT_PATTERN).build();
return InstantPatternFormatter.newBuilder()
.setPattern(NamedPattern.DEFAULT.getNonLegacyPattern())
.build();
}

private static InstantFormatter createFormatterUnsafely(@Nullable final String[] options) {
Expand Down Expand Up @@ -94,7 +94,7 @@ private static InstantFormatter createFormatterUnsafely(@Nullable final String[]
private static String readPattern(@Nullable final String[] options) {
return options != null && options.length > 0 && options[0] != null
? decodeNamedPattern(options[0])
: DEFAULT_PATTERN;
: NamedPattern.DEFAULT.getNonLegacyPattern();
}

/**
Expand Down Expand Up @@ -140,53 +140,14 @@ static String decodeNamedPattern(final String pattern) {
// This is the correct behaviour for `SimpleDateFormat`.
// Though `X` in `DateTimeFormatter` produces `Z` for zero-offset.
// To avoid the `Z` output, one needs to use `x` with `DateTimeFormatter`.
final boolean compat = InstantPatternFormatter.LEGACY_FORMATTERS_ENABLED;

switch (pattern) {
case "ABSOLUTE":
return "HH:mm:ss,SSS";
case "ABSOLUTE_MICROS":
return "HH:mm:ss," + (compat ? "nnnnnn" : "SSSSSS");
case "ABSOLUTE_NANOS":
return "HH:mm:ss," + (compat ? "nnnnnnnnn" : "SSSSSSSSS");
case "ABSOLUTE_PERIOD":
return "HH:mm:ss.SSS";
case "COMPACT":
return "yyyyMMddHHmmssSSS";
case "DATE":
return "dd MMM yyyy HH:mm:ss,SSS";
case "DATE_PERIOD":
return "dd MMM yyyy HH:mm:ss.SSS";
case "DEFAULT":
return "yyyy-MM-dd HH:mm:ss,SSS";
case "DEFAULT_MICROS":
return "yyyy-MM-dd HH:mm:ss," + (compat ? "nnnnnn" : "SSSSSS");
case "DEFAULT_NANOS":
return "yyyy-MM-dd HH:mm:ss," + (compat ? "nnnnnnnnn" : "SSSSSSSSS");
case "DEFAULT_PERIOD":
return "yyyy-MM-dd HH:mm:ss.SSS";
case "ISO8601_BASIC":
return "yyyyMMdd'T'HHmmss,SSS";
case "ISO8601_BASIC_PERIOD":
return "yyyyMMdd'T'HHmmss.SSS";
case "ISO8601":
return "yyyy-MM-dd'T'HH:mm:ss,SSS";
case "ISO8601_OFFSET_DATE_TIME_HH":
return "yyyy-MM-dd'T'HH:mm:ss,SSS" + (compat ? "X" : "x");
case "ISO8601_OFFSET_DATE_TIME_HHMM":
return "yyyy-MM-dd'T'HH:mm:ss,SSS" + (compat ? "XX" : "xx");
case "ISO8601_OFFSET_DATE_TIME_HHCMM":
return "yyyy-MM-dd'T'HH:mm:ss,SSS" + (compat ? "XXX" : "xxx");
case "ISO8601_PERIOD":
return "yyyy-MM-dd'T'HH:mm:ss.SSS";
case "ISO8601_PERIOD_MICROS":
return "yyyy-MM-dd'T'HH:mm:ss." + (compat ? "nnnnnn" : "SSSSSS");
case "US_MONTH_DAY_YEAR2_TIME":
return "dd/MM/yy HH:mm:ss.SSS";
case "US_MONTH_DAY_YEAR4_TIME":
return "dd/MM/yyyy HH:mm:ss.SSS";
try {
final NamedPattern namedPattern = NamedPattern.valueOf(pattern);
return InstantPatternFormatter.LEGACY_FORMATTERS_ENABLED
? namedPattern.getLegacyPattern()
: namedPattern.getNonLegacyPattern();
} catch (IllegalArgumentException ignored) { // for Java 22+ it can be changed to `IllegalArgumentException _`
return pattern;
}
return pattern;
}

private static TimeZone readTimeZone(@Nullable final String[] options) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to you under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.logging.log4j.core.pattern;

@SuppressWarnings("SpellCheckingInspection")
public enum NamedPattern {
ABSOLUTE("HH:mm:ss,SSS", "HH:mm:ss,SSS"),
ABSOLUTE_MICROS("HH:mm:ss,nnnnnn", "HH:mm:ss,SSSSSS"),
ABSOLUTE_NANOS("HH:mm:ss,nnnnnnnnn", "HH:mm:ss,SSSSSSSSS"),
ABSOLUTE_PERIOD("HH:mm:ss.SSS", "HH:mm:ss.SSS"),
COMPACT("yyyyMMddHHmmssSSS", "yyyyMMddHHmmssSSS"),
DATE("dd MMM yyyy HH:mm:ss,SSS", "dd MMM yyyy HH:mm:ss,SSS"),
DATE_PERIOD("dd MMM yyyy HH:mm:ss.SSS", "dd MMM yyyy HH:mm:ss.SSS"),
DEFAULT("yyyy-MM-dd HH:mm:ss,SSS", "yyyy-MM-dd HH:mm:ss,SSS"),
DEFAULT_MICROS("yyyy-MM-dd HH:mm:ss,nnnnnn", "yyyy-MM-dd HH:mm:ss,SSSSSS"),
DEFAULT_NANOS("yyyy-MM-dd HH:mm:ss,nnnnnnnnn", "yyyy-MM-dd HH:mm:ss,SSSSSSSSS"),
DEFAULT_PERIOD("yyyy-MM-dd HH:mm:ss.SSS", "yyyy-MM-dd HH:mm:ss.SSS"),
ISO8601_BASIC("yyyyMMdd'T'HHmmss,SSS", "yyyyMMdd'T'HHmmss,SSS"),
ISO8601_BASIC_PERIOD("yyyyMMdd'T'HHmmss.SSS", "yyyyMMdd'T'HHmmss.SSS"),
ISO8601("yyyy-MM-dd'T'HH:mm:ss,SSS", "yyyy-MM-dd'T'HH:mm:ss,SSS"),
ISO8601_OFFSET_DATE_TIME_HH("yyyy-MM-dd'T'HH:mm:ss,SSSX", "yyyy-MM-dd'T'HH:mm:ss,SSSx"),
ISO8601_OFFSET_DATE_TIME_HHMM("yyyy-MM-dd'T'HH:mm:ss,SSSXX", "yyyy-MM-dd'T'HH:mm:ss,SSSxx"),
ISO8601_OFFSET_DATE_TIME_HHCMM("yyyy-MM-dd'T'HH:mm:ss,SSSXXX", "yyyy-MM-dd'T'HH:mm:ss,SSSxxx"),
ISO8601_PERIOD("yyyy-MM-dd'T'HH:mm:ss.SSS", "yyyy-MM-dd'T'HH:mm:ss.SSS"),
ISO8601_PERIOD_MICROS("yyyy-MM-dd'T'HH:mm:ss.nnnnnn", "yyyy-MM-dd'T'HH:mm:ss.SSSSSS"),
US_MONTH_DAY_YEAR2_TIME("dd/MM/yy HH:mm:ss.SSS", "dd/MM/yy HH:mm:ss.SSS"),
US_MONTH_DAY_YEAR4_TIME("dd/MM/yyyy HH:mm:ss.SSS", "dd/MM/yyyy HH:mm:ss.SSS");
private final String legacyPattern, nonLegacyPattern;

NamedPattern(String legacyPattern, String nonLegacyPattern) {
this.legacyPattern = legacyPattern;
this.nonLegacyPattern = nonLegacyPattern;
}

public String getLegacyPattern() {
return legacyPattern;
}

public String getNonLegacyPattern() {
return nonLegacyPattern;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<entry xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://logging.apache.org/xml/ns"
xsi:schemaLocation="https://logging.apache.org/xml/ns https://logging.apache.org/xml/ns/log4j-changelog-0.xsd"
type="changed">
<description format="asciidoc">Exported named-patterns into its own public enum</description>
</entry>
Loading