Skip to content

DatePatternConverter incorrectly converting date pattern since Log4J 2.25.0 #3930

@tanmaybaid

Description

@tanmaybaid

Description

DatePatternConverter incorrectly converting date pattern with starting Log4J 2.25.0 for following usecases:\

Usecase 1: Date pattern contains , (comma followed by a whitespace)

Example: %date{EEE, dd MMM yyyy HH:mm:ss zzz}{GMT}
Actual: Thu,' 18 Sep 2025 00:42:14 GMT
Expected: Thu, 18 Sep 2025 00:42:14 GMT

Usecase 2: Date pattern contains , (whitespace followed by a comma)

Example: %date{EEE ,dd MMM yyyy HH:mm:ss zzz}{GMT}
Actual: Thu ',18 Sep 2025 00:42:14 GMT
Expected: Thu, 18 Sep 2025 00:42:14 GMT

Usecase 3: Date pattern contains (two consecutive whitespaces)

Example: %date{EEE dd MMM yyyy HH:mm:ss zzz}{GMT}
Actual: Thu ' 18 Sep 2025 00:42:14 GMT
Expected: Thu 18 Sep 2025 00:42:14 GMT

Root Cause:

The issue is related to the "Date & Time Formatting" changes introduced in Log4J 2.25.0 as described here:
https://logging.apache.org/log4j/2.x/release-notes.html#release-notes-2-25-0-instant-format

Mitigation:

This issue is resolved by setting the log4j2.instantFormatter property to legacy

Configuration

Pattern layout with date pattern that includes , (comma followed by a whitespace) or , (whitespace followed by a comma) or (two consecutive whitespaces) - see usecases above with examples.

Version: 2.25.0

Operating system: MacOS and Linux

JDK: amazon-corretto-21.jdk and amazon-corretto-17.jdk

Logs

N/A

Reproduction

Pull request #3931 adds tests that fail due to this bug.

Metadata

Metadata

Assignees

Labels

bugIncorrect, unexpected, or unintended behavior of existing codelayoutsAffects one or more Layout plugins

Type

Projects

Status

Done

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions