Skip to content

How to get exception class name via pattern #2495

Answered by vy
der-eismann asked this question in Q&A
Discussion options

You must be logged in to vote

@der-eismann, Log4j 2 contains a GELF Layout. But all JSON-based layouts (i.e., JSON Layout and GELF Layout) are deprecated in favor of JSON Template Layout (JTL), which provides unmatched customizability and performance compared to other JSON-based layouts in both Log4j and other logging implementations.

JTL already ships a GELF-compatible layout out of the box. You can use it as follows in your log4j2.xml:

<JsonTemplateLayout eventTemplateUri="classpath:GelfLayout.json"/>

You can extend the GelfLayout.json event template to include the exception class name as follows:

<JsonTemplateLayout eventTemplateUri="classpath:GelfLayout.json">
  <EventTemplateAdditionalField key="exceptionClassName"

Replies: 1 comment 5 replies

Comment options

vy
Apr 22, 2024
Collaborator

You must be logged in to vote
5 replies
@der-eismann
Comment options

@vy
Comment options

vy Apr 22, 2024
Collaborator

@der-eismann
Comment options

@vy
Comment options

vy Apr 22, 2024
Collaborator

@der-eismann
Comment options

Answer selected by der-eismann
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants