Hi Naz,

Volkan has contributed a fantastic json template layout that I expect will do 
what you want, however it has not been released yet.
https://github.com/apache/logging-log4j2/pull/335

This discussion from the mailing list provides several options which may be 
relevant to your use case:
https://lists.apache.org/thread.html/r538bb480c6d92813224b6a207e34210cccebc01e8d1781943d0ce32d%40%3Clog4j-user.logging.apache.org%3E

> But my custom json layout doesn't write into a file. Do I have to write a 
> file appender for that?

Layout implementations can be configured with any appender, the existing file 
based appenders
work with custom layouts. The layout is responsible for converting a LogEvent 
into a format (e.g. bytes) that
can be written to an appender (file, socket, standard out, etc) without being 
aware of the appenders
implementation details.

Best,
-ck

On Wed, Aug 12, 2020, at 09:56, Naz S wrote:
> Hi,
> 
> I'm trying to use JSON layout for a logging format. When I use the default
> JSON Layout, I see that there are some fields which are unnecessary to me
> (for example, loggerFqcn, endOfBatch, etc).
> 
> Then I decided to implement a custom JSON layout. But I see that
> JacksonFactory is not visible outside the package. Now I get only necessary
> fields from LogEvent and generate JSON format using JSON generator. Every
> configuration is done by code. But ultimately I want to configure fields in
> log4j2.xml file. Any suggestions?
> 
> Also I would like to write logs into a log file. But my custom json layout
> doesn't write into a file. Do I have to write a file appender for that?
> 
> Many thanks,
> 

Reply via email to