Skip to content

Insert ObjectMessage as JSON when using JsonTemplateLayout #1939

Answered by vy
svh-06 asked this question in Q&A
Discussion options

You must be logged in to vote

For one, we strongly recommend all Gelf- and JsonLayout users to migrate to JsonTemplateLayout, JTL for short. It is feature-rich, faster, and customizable; simply better. Hence, you are on the right path.

JTL falls back to Object#toString() for types that are not known to it. Earlier I created LOG4J2-3082 to allow JTL to use external serializers (e.g., Jackson) too, though I am swamped with other Log4j priorities. Though you can still achieve this using a custom message resolver.

Creating a custom message resolver

You need to create a custom message resolver and its factory. See the Extending section of the JTL manual for an example. There you can reuse code from org.apache.logging.log4j…

Replies: 6 comments 12 replies

Comment options

vy
Nov 2, 2023
Collaborator

You must be logged in to vote
2 replies
@brianmaresca
Comment options

@vy
Comment options

vy Aug 3, 2024
Collaborator

Answer selected by svh-06
Comment options

You must be logged in to vote
1 reply
@vy
Comment options

vy Jul 18, 2024
Collaborator

Comment options

You must be logged in to vote
2 replies
@vy
Comment options

vy Jul 18, 2024
Collaborator

@ppkarwasz
Comment options

Comment options

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

@vy
Comment options

vy Jul 18, 2024
Collaborator

@vy
Comment options

vy Jul 18, 2024
Collaborator

Comment options

You must be logged in to vote
4 replies
@miberg81
Comment options

@vy
Comment options

vy Jul 26, 2024
Collaborator

@miberg81
Comment options

@miberg81
Comment options

Comment options

vy
Jul 29, 2024
Collaborator

You must be logged in to vote
0 replies
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