Hi Amanda,

I am crossposting this to dev@logging.apache.org. Please answer to
that mailing list.

On Tue, 6 Aug 2024 at 01:05, Amanda Liu <as...@terpmail.umd.edu> wrote:
> The reason I want a custom appender is to pretty print the JSON log objects 
> produced by JsonTemplateLayout, to make it more readable. I see in the log4j 
> docs that JSON pretty print is supported in JsonLayout, but not 
> JsonTemplateLayout. I don't want to use JsonLayout, since it's deprecated and 
> doesn't support some other features that JSONTemplateLayout has.
>
> Is there any strong reason why JsonTemplateLayout does not support JSON 
> pretty print? Or could I contribute to the JsonTemplateLayout file in the 
> log4j repo to add this feature? (here: 
> https://github.com/apache/logging-log4j2/blob/a884e991c1a551cb321b2efed770a15fbc55aa2b/log4j-layout-template-json/src/main/java/org/apache/logging/log4j/layout/template/json/JsonTemplateLayout.java).
>  This would resolve my issue, and I think other log4j JsonTemplateLayout 
> users may be interested in the pretty print feature.

There is no special reason why `JsonTemplateLayout` does not support
pretty print. It was simply never implemented.

Currently JTL only writes to a small `JsonWriter`[1] class through
`TemplateResolver.resolve()`[2]. This could be easily generalized
(probably in `3.x`) by replacing `JsonWriter` with an interface, to
support multiple serialization formats. There is already a JIRA issue
for that (see LOG4J2-3082[0]).

Admittedly this requires quite some work, but it is within the grasp
of a semester-long student project or Google Summer of Code.

If you are willing to contribute such a feature, we can always assist
you with the Log4j-related details.

Piotr

BTW: I added more info about shading applications that use Log4j Core
to our documentation[3]

[0] https://issues.apache.org/jira/browse/LOG4J2-3082
[1] 
https://javadoc.io/static/org.apache.logging.log4j/log4j-layout-template-json/2.19.0/org/apache/logging/log4j/layout/template/json/util/JsonWriter.html
[2] 
https://javadoc.io/static/org.apache.logging.log4j/log4j-layout-template-json/2.19.0/org/apache/logging/log4j/layout/template/json/resolver/TemplateResolver.html#resolve-V-org.apache.logging.log4j.layout.template.json.util.JsonWriter-
[3] 
https://github.com/apache/logging-log4j2/blob/2.x/src/site/antora/modules/ROOT/pages/faq.adoc#how-do-i-create-a-single-jar-application-containing-log4j-core

Reply via email to