Re: Unable to locate plugin type for Custom log4j2 Appender
"Piotr P. Karwasz" <[email protected]> Tue, 13 Aug 2024 20:50:59 +0200
| Newsgroups | gmane.comp.jakarta.log4j.user,gmane.comp.jakarta.lucene.net.devel |
|---|---|
| Message-ID | <CAFmygFYHq5caznv7e-7Bjdw8AvO=iJHJi3on8PgZiWkD0eaMhw@mail.gmail.com> |
Hi Amanda, I am crossposting this to [email protected]. Please answer to that mailing list. On Tue, 6 Aug 2024 at 01:05, Amanda Liu <[email protected]> wrote: > The reason I want a custom appender is to pretty print the JSON log objec= ts produced by JsonTemplateLayout, to make it more readable. I see in the l= og4j docs that JSON pretty print is supported in JsonLayout, but not JsonTe= mplateLayout. I don't want to use JsonLayout, since it's deprecated and doe= sn't support some other features that JSONTemplateLayout has. > > Is there any strong reason why JsonTemplateLayout does not support JSON p= retty print? Or could I contribute to the JsonTemplateLayout file in the lo= g4j repo to add this feature? (here: https://github.com/apache/logging-log4= j2/blob/a884e991c1a551cb321b2efed770a15fbc55aa2b/log4j-layout-template-json= /src/main/java/org/apache/logging/log4j/layout/template/json/JsonTemplateLa= yout.java). This would resolve my issue, and I think other log4j JsonTempla= teLayout 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-templat= e-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-templat= e-json/2.19.0/org/apache/logging/log4j/layout/template/json/resolver/Templa= teResolver.html#resolve-V-org.apache.logging.log4j.layout.template.json.uti= l.JsonWriter- [3] https://github.com/apache/logging-log4j2/blob/2.x/src/site/antora/modul= es/ROOT/pages/faq.adoc#how-do-i-create-a-single-jar-application-containing-= log4j-core