# Logging fields with type long using logback-ecs-encoder

**URL:** <https://discuss.elastic.co/t/logging-fields-with-type-long-using-logback-ecs-encoder/372031>\
**Category:** Logs\
**Tags:** java\
**Created:** [December 16, 2024, 3:46pm UTC](https://discuss.elastic.co/t/logging-fields-with-type-long-using-logback-ecs-encoder/372031 "2024-12-16T15:46:25Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![softarn](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/softarn/32/140049_2.png) [@softarn](https://discuss.elastic.co/u/softarn)\
**Post date:** [December 16, 2024, 3:46pm UTC](https://discuss.elastic.co/t/logging-fields-with-type-long-using-logback-ecs-encoder/372031/1 "2024-12-16T15:46:25Z")

</div>

I'm adding request/response logging to my Spring Boot application and I want to add, for example, the field `http.request.body.bytes` which is of type long.

Currently we are adding the values we want to in MDC, logging and then immediately removing it from MDC

```auto
MDC.put("http.request.body.bytes", "2513");
log.info("Http request");
MDC.remove("http.request.body.bytes");

```

Are we misusing the purpose of MDC class? How do I do this and get it in number type which is the correct type according to ECS field documentation?

> **[HTTP Fields | Elastic Common Schema (ECS) Reference \[8.16\] | Elastic](https://www.elastic.co/guide/en/ecs/current/ecs-http.html#field-http-request-body-bytes)**

---

<div class="post-metadata">

**Author:** ![Jonas\_Kunz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jonas_kunz/32/110740_2.png) [@Jonas\_Kunz](https://discuss.elastic.co/u/Jonas_Kunz)\
**Post date:** [December 18, 2024, 1:20pm UTC](https://discuss.elastic.co/t/logging-fields-with-type-long-using-logback-ecs-encoder/372031/2 "2024-12-18T13:20:39Z")

</div>

The MDC is usually used to pass information down the call-stack as "implicit arguments" to be attached to every log message. E.g. usually things like the username for a request are put into the MDC, so that all logs for that request processing include the username.

Your use-case seems more of a workaround for adding additional fields in addition to the message to the logs. So if possible you should look into [structured logging](https://www.elastic.co/guide/en/ecs-logging/java/current/_structured_logging_with_log4j2.html) instead, which also gives you the option to preserve the types of values you add. The MDC API works only with strings.
