Re: PatternLayout Vs JsonTemplateLayout/JsonLayout Performance Comparision

"Carter Kozak" <[email protected]> Wed, 16 Nov 2022 12:22:19 -0500
Newsgroups gmane.comp.jakarta.log4j.user
Message-ID <[email protected]>
On Wed, Nov 16, 2022, at 12:09, Christopher Schultz wrote:
> Is it even possible to use PatternLayout safely with JSON-encoded data? 
> What if you log a username which contains a " character? Won't that 
> completely break your JSON?

This can be done using the %encode pattern described in the documentation:
https://logging.apache.org/log4j/2.x/manual/layouts.html#PatternLayout
It provides the following example: {"message": "%enc{%m}{JSON}"}

> I think performance shouldn't be your primary consideration, here.

I agree wholeheartedly with this sentiment, but we should remember
that some users have a different set of constraints and requirements.

Carter Kozak