You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Rfc5424Layout prints null as the timestamp of an event 1 ms before the epoch #4490
bugIncorrect, unexpected, or unintended behavior of existing codelayoutsAffects one or more Layout pluginspriority: P3Enhancement, documentation, tests or build
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
@Testvoidrfc5424BeforeTheEpoch() { // with a UTC default time zonefinalRfc5424Layoutlayout = Rfc5424Layout.newBuilder().setAppName("app").build();
finalLogEventevent = Log4jLogEvent.newBuilder().setTimeMillis(-1).build();
finalStringtimestamp = 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.
bugIncorrect, unexpected, or unintended behavior of existing codelayoutsAffects one or more Layout pluginspriority: P3Enhancement, documentation, tests or build
Activity