elastic / ecs-logging-java

https://www.elastic.co/guide/en/ecs-logging/java/current/intro.html
Apache License 2.0
141 stars 76 forks source link

Add support for custom MdcSerializer in EcsLayout #291

Open aliaksandr-lavishak-tde opened 3 days ago

aliaksandr-lavishak-tde commented 3 days ago

Summary

EcsLayout from log4j2-ecs-layout currently uses a hardcoded implementation of MdcSerializer for MDC serialization. While this works well for most cases, it lacks flexibility for users with custom MDC serialization requirements.

I propose adding support for configuring or overriding the MdcSerializer implementation to accommodate specific use cases, such as:

Problem Statement

The current implementation of MdcSerializer is resolved dynamically using MdcSerializer.Resolver. However, it does not allow users to provide their own MdcSerializer implementation.

Proposed Solution

Introduce a mechanism to customize the MdcSerializer, such as already implemented for ObjectMessageJacksonSerializer

aliaksandr-lavishak-tde commented 19 hours ago

I created an example implementation of how it could look. https://github.com/elastic/ecs-logging-java/pull/293