ramanathan1504 opened a new issue, #4490:
URL: https://github.com/apache/logging-log4j2/issues/4490

   `Rfc5424Layout` caches the last formatted timestamp in an instance field. 
The cache starts with the time `-1` and no string. An event at exactly `-1` ms 
matches that seed, so the layout writes the four characters `null` as TIMESTAMP:
   
   ```
   <134>1 null localhost app 15847 - - m
   ```
   
   The expected record is `<134>1 1969-12-31T23:59:59.999Z localhost app 15847 
- - m`. RFC 5424 can express this time, since `DATE-FULLYEAR` is four digits. 
`NILVALUE` is only for an application that cannot obtain the time, so `-` is 
not the right output either.
   
   The record stays `null` for every `-1` ms event until an event with another 
time reaches the same layout. After that, `-1` ms formats correctly. An event 
at `-2` ms is always correct. `SyslogAppender` with `format="RFC5424"` uses the 
same layout.
   
   Seeding the cache with `Long.MIN_VALUE`, as `CachedDateFormat` does, fixes 
it. Times before the epoch are rare in logs, so this is not urgent. 
`InstantPatternThreadLocalCachedFormatter` has the same `-1` seed, which is 
being discussed on #4322.
   
   ## Configuration
   
   **Version:** `2.x` at `ea28f5a` and `main` at `2bb673f`. Also 2.17.2, 
2.24.3, 2.26.1 and 3.0.0-beta3. The code dates from the first version of the 
layout.
   
   **Operating system:** any. Reproduced on macOS.
   
   **JDK:** 17
   
   ## Logs
   
   None.
   
   ## Reproduction
   
   ```java
   @Test
   void rfc5424BeforeTheEpoch() { // with a UTC default time zone
       final Rfc5424Layout layout = 
Rfc5424Layout.newBuilder().setAppName("app").build();
       final LogEvent event = 
Log4jLogEvent.newBuilder().setTimeMillis(-1).build();
       final String timestamp = layout.toSerializable(event).split(" ")[1];
       assertEquals("1969-12-31T23:59:59.999Z", timestamp); // actual: null
   }
   ```
   
   ## Related
   
   The same method does not pad the year to four digits, and 
`GregorianCalendar` uses the Julian calendar before 1582. An event in the year 
999 prints `999-06-10T00:00:00.000Z` instead of `0999-06-15T00:00:00.000Z`. 
That is a separate defect.


-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to