Log4j MDC (Mapped Diagnostic Context) : Example code
Log4j MDC (Mapped Diagnostic Context) : Example code As a continuation of my previous post about Log4j MDC (Mapped Diagnostic Context) , here's a fully working code sample explaining the concept. This is a simple example where we have a one servlet and one filter. The filter intercepts each and every request and put the user name in the MDC. The Servlet Class: package com.veerasundar.code.log4jmdc; import java.io.IOException; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.log4j.Logger; /** * A good-for-nothing servlet which is just writing few messages to the logger * object. Since we've configured in the log4j.properties file to include the * userName, taken from MDC,Read full article from Log4j MDC (Mapped Diagnostic Context) : Example code
No comments:
Post a Comment