You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@logging.apache.org by "SebTardif (via GitHub)" <gi...@apache.org> on 2026/07/25 11:33:42 UTC

[PR] fix: InstantPatternLegacyFormatter precision for legacy n patterns [logging-log4j2]

SebTardif opened a new pull request, #4220:
URL: https://github.com/apache/logging-log4j2/pull/4220

   ## What Problem This Solves
   
   `InstantPatternLegacyFormatter` computed precision by constructing `InstantPatternDynamicFormatter` with the **legacy** pattern string. Legacy FixedDateFormat patterns use `n` for variable-length fractional seconds. DateTimeFormatter treats `n` as always nano-of-second, so patterns such as `yyyy-MM-dd HH:mm:ss,nnnnnn` were classified as `NANOS` instead of `MICROS`, breaking cache invalidation for legacy formatters.
   
   ## Evidence
   
   Issue #3816. Approach matches ppkarwasz's fix on main (`n` → `S` before precision detection), which was not present on `2.x`.
   
   ### Red-green
   
   Without the fix:
   
   ```
   expected: Micros
    but was: Nanos
   ```
   
   With the fix:
   
   ```bash
   export JAVA_HOME=$(/usr/libexec/java_home -v 17)
   ./mvnw -pl log4j-core,log4j-core-test -am test \
     -Dtest=InstantPatternLegacyFormatterPrecisionTest,NamedInstantPatternTest \
     -Dsurefire.failIfNoSpecifiedTests=false
   ```
   
   `InstantPatternLegacyFormatterPrecisionTest`: 2 passed  
   `NamedInstantPatternTest`: 21 passed (also asserts legacy/modern precision parity)
   
   ## Summary
   
   - Map legacy `n` to `S` only for precision detection
   - Dedicated precision unit tests + NamedInstantPattern precision assertion
   - Changelog; Fixes #3816


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@logging.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] fix: InstantPatternLegacyFormatter precision for legacy n patterns [logging-log4j2]

Posted by "vy (via GitHub)" <gi...@apache.org>.
vy commented on code in PR #4220:
URL: https://github.com/apache/logging-log4j2/pull/4220#discussion_r3774191167


##########
src/changelog/.2.x.x/3816_legacy_instant_pattern_precision.xml:
##########
@@ -0,0 +1,8 @@
+<?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="fixed">
+  <issue id="3816" link="https://github.com/apache/logging-log4j2/issues/3816"/>
+  <description format="asciidoc">Fix precision detection in `InstantPatternLegacyFormatter` for legacy fractional-second patterns using `n`</description>

Review Comment:
   ```suggestion
     <issue id="3816" link="https://github.com/apache/logging-log4j2/issues/3816"/>
     <issue id="3816" link="https://github.com/apache/logging-log4j2/issues/3816"/>
     <description format="asciidoc">Fix precision detection in `InstantPatternLegacyFormatter` for legacy fractional-second patterns using `n`</description>
   ```



##########
src/changelog/.2.x.x/3816_legacy_instant_pattern_precision.xml:
##########
@@ -0,0 +1,8 @@
+<?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="fixed">
+  <issue id="3816" link="https://github.com/apache/logging-log4j2/issues/3816"/>
+  <description format="asciidoc">Fix precision detection in `InstantPatternLegacyFormatter` for legacy fractional-second patterns using `n`</description>

Review Comment:
   ```suggestion
     <issue id="3816" link="https://github.com/apache/logging-log4j2/issues/3816"/>
     <issue id="3816" link="https://github.com/apache/logging-log4j2/issues/3816"/>
     <description format="asciidoc">Fix precision detection in `InstantPatternLegacyFormatter` for legacy fractional-second patterns using `n`</description>
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@logging.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] fix: `InstantPatternLegacyFormatter` precision for legacy `n` patterns [logging-log4j2]

Posted by "vy (via GitHub)" <gi...@apache.org>.
vy merged PR #4220:
URL: https://github.com/apache/logging-log4j2/pull/4220


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@logging.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] fix: InstantPatternLegacyFormatter precision for legacy n patterns [logging-log4j2]

Posted by "vy (via GitHub)" <gi...@apache.org>.
vy commented on code in PR #4220:
URL: https://github.com/apache/logging-log4j2/pull/4220#discussion_r3774202319


##########
src/changelog/.2.x.x/3816_legacy_instant_pattern_precision.xml:
##########
@@ -0,0 +1,8 @@
+<?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="fixed">
+  <issue id="3816" link="https://github.com/apache/logging-log4j2/issues/3816"/>
+  <description format="asciidoc">Fix precision detection in `InstantPatternLegacyFormatter` for legacy fractional-second patterns using `n`</description>

Review Comment:
   ```suggestion
     <issue id="3816" link="https://github.com/apache/logging-log4j2/issues/3816"/>
     <issue id="4220" link="https://github.com/apache/logging-log4j2/pull/4220"/>
     <description format="asciidoc">
       Fix precision detection in legacy date &amp; time pattern formatting
     </description>
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@logging.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org