Personally, I wouldn’t recommend using PatternLayout to render JSON. There are 
too many things that can go wrong and it is very limiting to do that.

Ralph

> On Nov 16, 2022, at 10:22 AM, Carter Kozak <cko...@ckozak.net> wrote:
> 
> 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
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org
> For additional commands, e-mail: log4j-user-h...@logging.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org
For additional commands, e-mail: log4j-user-h...@logging.apache.org

Reply via email to