Skip to content

Best way to log exceptions #2210

Answered by vy
mind-fuzzy asked this question in Q&A
Jan 18, 2024 · 3 comments · 3 replies
Discussion options

You must be logged in to vote

Above method can lead to high object allocation rate especially with printing full stack trace and using the pattern layout.

@mind-fuzzy, not necessarily. If you choose a layout (e.g., PatternLayout, JsonTemplateLayout) and appender combination that supports garbage-free logging and configure them right (not all configuration options are garbage-free), you will have a blazing fast logging that is not possible with any other Log4j competitors.

As a matter of fact, JsonTemplateLayout has no allocations itself while serializing stack traces except while getting the stack trace using Throwable#getStackTrace(), which incurs a clone operation in JDK where no Log4j has no influence on. (Patter…

Replies: 3 comments 3 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
3 replies
@garydgregory
Comment options

@mind-fuzzy
Comment options

@vy
Comment options

vy Jan 18, 2024
Collaborator

Comment options

vy
Jan 18, 2024
Collaborator

You must be logged in to vote
0 replies
Answer selected by mind-fuzzy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
5 participants