Adding MDC headers to every Spring MVC request
Mapped Diagnostic Context ( MDC ) logging allows you to set attributes associated with current thread, so that SLF4J (via your logger implementation library) can log those attributes with each logging statement without it having to be specified. For example you could configure logback to log the sessionId on every statement, which is really handy when using a log indexer such as Splunk. This would allow you to easily see all the requests made by a user, for a given session. To use with logback, you'd set the pattern to %-4r [%thread] %-5level sessionId=%X{sessionId} - %msg%n Setting these attributes for each entry point would be a pain so one way would be to implement a ServletRequestListener , which would allow setting the attributes at the start of the request and removing them again at the end of the request. ( Note: It's important to remove the attributes afterwards, as threads are re-used by application servers and will give misleading logging statements) If you...