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
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 instead, which also gives you the option to preserve the types of values you add. The MDC API works only with strings.
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.