[MS25 & MS26] Unified date & time formatting #3139
Labels
layouts
Affects one or more Layout plugins
performance
Issues or PRs that affect performance, throughput, latency, etc.
STF-Milestones
Milestones funded by the Sovereign Tech Fund
Milestone
In #3121, date & time formatting of both Pattern Layout and JSON Template Layout has been rewritten to be served from a unified utility using Java's
DateTimeFormatter
under the hood with some caching for extra efficiency.Historical account
MS25, MS26, MS27 had the following sequence of goals:
InstantFormatter
(used for formatting log event instants) oflog4j-layout-template-json
tolog4j-core
InstantFormatter
moved tolog4j-core
in both JSON Template Layout and Pattern LayoutInstantFormatter
moved tolog4j-core
in other places where date & time formatting is neededWe encountered several blockers while executing this plan. Some highlights from the thinking process that led us to the current plan are shared below – see this
dev@
discussion for details.FixedDateFormat
andFastDateFormat
.InstantFormatter
leverages these two for date & time formatters for patterns they support, otherwise it falls back toDateTimeFormatter
.InstantFormatter
is moved tolog4j-core
and wired to Pattern Layout, several tests started failing, because previously employedFixedDateFormat
isn
andx
directivesFixedDateFormat
incorrectly calculates DST forAmerica/Santiago
time zone #2943)FastDateFormat
was copied from Commons Lang in 2015In short,
FixedDateFormat
andFastDateFormat
are liabilities (containing incorrect behaviour and bugs!) that once made sense for performance reasons. Though as shown with performance figures in #3121, the efficiency offered by this liability burden is negligible in the big picture of an end-to-end logging scenario. Eventually, we decided toDateTimeFormatter
for date & time formatting2024-10-29T14:49:53.997Z
form, we only need to generate53.997
each time and the rest can be precomputed per minute, cached, and reused)FixedDateFormat
andFastDateFormat
et al.FixedDateFormat
incorrectly calculates DST forAmerica/Santiago
time zone #2943Log4j 3
#3150 ports #3121 from
2.x
tomain
, the Log4j 3 branch.The text was updated successfully, but these errors were encountered: