Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MS25 & MS26] Unified date & time formatting #3139

Closed
vy opened this issue Oct 29, 2024 · 1 comment
Closed

[MS25 & MS26] Unified date & time formatting #3139

vy opened this issue Oct 29, 2024 · 1 comment
Assignees
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

Comments

@vy
Copy link
Member

vy commented Oct 29, 2024

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:

  • [MS25] Move the InstantFormatter (used for formatting log event instants) of log4j-layout-template-json to log4j-core
  • [MS26] Use the InstantFormatter moved to log4j-core in both JSON Template Layout and Pattern Layout
  • [MS27] Use the InstantFormatter moved to log4j-core in other places where date & time formatting is needed

We 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.

  • Log4j contains two custom date & time formatting utilities for performance reasons: FixedDateFormat and FastDateFormat.
  • InstantFormatter leverages these two for date & time formatters for patterns they support, otherwise it falls back to DateTimeFormatter.
  • Once InstantFormatter is moved to log4j-core and wired to Pattern Layout, several tests started failing, because previously employed FixedDateFormat is
  • FastDateFormat was copied from Commons Lang in 2015
  • No other logging frameworks (Logback, Tinylog, etc.) had similar date & time formatting optimizations

In short, FixedDateFormat and FastDateFormat 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 to

Log4j 3

#3150 ports #3121 from 2.x to main, the Log4j 3 branch.

@vy vy added performance Issues or PRs that affect performance, throughput, latency, etc. STF-Milestones Milestones funded by the Sovereign Tech Fund layouts Affects one or more Layout plugins labels Oct 29, 2024
@vy vy added this to the 2.25.0 milestone Oct 29, 2024
@vy vy self-assigned this Oct 29, 2024
@grobmeier
Copy link
Member

Thanks, looks good to me!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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
Projects
None yet
Development

No branches or pull requests

2 participants