Hi Volkan,

[I am dropping `log4j-user@logging` from the recipients]

On Wed, 14 Aug 2024 at 10:24, Volkan Yazıcı <vol...@yazi.ci.invalid> wrote:
> On Tue, Aug 13, 2024 at 8:52 PM Piotr P. Karwasz <piotr.karw...@gmail.com>
> wrote:
> > There is no special reason why `JsonTemplateLayout` does not support
> > pretty print. It was simply never implemented.
>
> See my response to Amanda
> <https://lists.apache.org/thread/zz26313jbbz495qnokkwqjkwpos2llp7>, there
> are good reasons for not doing it. For one, we first need to start with
> answering "Why shall we do it?". If we hear a compelling use case, it is
> still technically not trivial due to `JsonWriter#writeRawString()` methods.
> Putting that detail aside, I am in favor of guiding users to choose the
> right tool for the right job, instead of trying to make every tool cater
> for all jobs.

When I say "pretty print", I mostly think about supporting BSON,
MessagePack, ByteBuffers and other binary formats. JSON "pretty print"
would be just a side-effect.

JTL is a great tool to:

1. Transform a log event into a Map<String, Object> in an extremely
configurable way.
2. Serialize the Map<String, Object> as JSON using a hardcoded JsonWriter.

Since the second part is hardcoded, we can not use JTL with the NoSQL
Appender. Using it with the JMS or JDBC appenders is limited to
storing strings.

> Making `JsonWriter` pluggable can indeed be a nice feature. It can even be
> served in Log4j 2 without breaking backward compatibility. But it is a
> pretty big undertaking. My suggestion is to implement a small enhancement
> that is simpler: falling back to an external serializer (e.g., Jackson) for
> unknown types. We can easily ship this in Log4j 2 and it addresses the use
> case stated in LOG4J2-3082
> <https://issues.apache.org/jira/browse/LOG4J2-3082>.

I think we have two different concerns here:

1. How to map `Message` implementations to a `String` or `Map<String,
predefined_subset_of_objects>`. I think these two conversions should
be hardcoded by the developer by creating the appropriate `Message`
implementation. So if somebody wants to log objects in their code, I
think they should provide a way to map those objects to a
`MapMessage`.
2. How to convert a Log Event into a byte array. As I stated above,
JTL already excels in converting this to a `Map<String,
predefined_subset_of_objects>`. It only needs to learn new
serialization formats.

Piotr

Reply via email to