[ 
https://issues.apache.org/jira/browse/LOG4J2-3082?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17488475#comment-17488475
 ] 

Michael Kendle commented on LOG4J2-3082:
----------------------------------------

We took a look at the custom resolver and noticed that the key part seemed to 
be the use of...
{code:java}
jsonWriter.writeRawString(valueJson); {code}
We also found that a MultiformatMessage makes use of this naturally. In our 
case, we've got a single object that we're wanting to log, so we were able to 
efficiently make that object implement MultiformatMessage and not use a custom 
resolver. However, this wouldn't have worked for us if we were wanting to log 
arbitrary objects, so while we've got a work around for this particular case, 
it would still be nice if this Jira is implemented for other use cases.

Thanks for the ideas in the meantime though!

> Support external serializers (e.g., Jackson) JsonTemplateLayout
> ---------------------------------------------------------------
>
>                 Key: LOG4J2-3082
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-3082
>             Project: Log4j 2
>          Issue Type: Improvement
>          Components: JsonTemplateLayout
>    Affects Versions: 2.14.1
>            Reporter: Schubert Fernandes
>            Assignee: Volkan Yazici
>            Priority: Minor
>         Attachments: log4j.json.event.layout.zip
>
>
> When using JsonTemplateLayout is there a way to output composite objects as 
> JSON?
> It looks like any composite objects are output as simple strings with the 
> value generated by the .toString() method of the Java object.
> Is there an option to output JSON instead, possibly using 
> _org.apache.logging.log4j.core.jackson.Log4jJsonObjectMapper_ ?
> It is currently possible to do this by converting the object into a 
> java.util.Map before supplying it to the logging framework but it would be 
> nice if the logging framework did this out of the box if an option is turned 
> on as it is not always possible to do this (e.g. with objects on the MDC/NDC).
> This should apply to composite objects logged from...
> # The thread context map (MDC).
> # The thread context stack (NDC).
> # Message parameters
> # anywhere else that I may have missed.
> See the differences between the two log messages generated in the attached 
> project.



--
This message was sent by Atlassian Jira
(v8.20.1#820001)

Reply via email to