Last active
August 29, 2017 10:37
-
-
Save radutoev/110d782438a901742741d77e59afc697 to your computer and use it in GitHub Desktop.
Add correlation id on log4j's ThreadContext
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class CorrelationIdFilter implements Filter { | |
@Override | |
public void init(FilterConfig filterConfig) throws ServletException { | |
} | |
@Override | |
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { | |
String correlationId = ((HttpServletRequest) request).getHeader("x-correlation-id"); | |
ThreadContext.put("correlationId", correlationId); | |
try { | |
chain.doFilter(request, response); | |
} finally { | |
ThreadContext.clearAll(); | |
} | |
} | |
@Override | |
public void destroy() { | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment