# Log4j2-ecs-layout serialize MDC

**URL:** <https://discuss.elastic.co/t/log4j2-ecs-layout-serialize-mdc/311623>\
**Category:** Logs\
**Created:** [August 8, 2022, 6:56am UTC](https://discuss.elastic.co/t/log4j2-ecs-layout-serialize-mdc/311623 "2022-08-08T06:56:04Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![tbglazer](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tbglazer/32/108324_2.png) [@tbglazer](https://discuss.elastic.co/u/tbglazer)\
**Post date:** [August 8, 2022, 6:56am UTC](https://discuss.elastic.co/t/log4j2-ecs-layout-serialize-mdc/311623/1 "2022-08-08T06:56:04Z")

</div>

Is there any option not to serialize MDC fields by default ?  
I am using additional fields to serialize under different name like \<KeyValuePair name="labels.X" value="%X(Y)" and as result I get two fields labels.X=value and Y=value.  
I would like not to generate Y=value.  
I would like also an option not to generate output for fields with null value.

---

<div class="post-metadata">

**Author:** ![matschaffer](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/matschaffer/32/95396_2.png) [@matschaffer](https://discuss.elastic.co/u/matschaffer)\
**Post date:** [August 22, 2022, 5:28am UTC](https://discuss.elastic.co/t/log4j2-ecs-layout-serialize-mdc/311623/2 "2022-08-22T05:28:44Z")

</div>

Hi there @tbglazer !

I'm not too familiar with this library, but if you have a full example it might be worth posting as an issue on [Issues · elastic/ecs-logging-java · GitHub](https://github.com/elastic/ecs-logging-java/issues)

The `%X(Y)` seems like it should be `%X{Y}` to me, but I could be misreading [Log4j – Log4j 2 Layouts](https://logging.apache.org/log4j/2.x/manual/layouts.html) for that.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [September 19, 2022, 5:29am UTC](https://discuss.elastic.co/t/log4j2-ecs-layout-serialize-mdc/311623/3 "2022-09-19T05:29:37Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
