[jboss-user] [JBoss Seam] - Re: Using log4j's NDC

atalaat do-not-reply at jboss.com
Wed Jun 20 15:39:48 EDT 2007


Try adding a servlet Filter, which manages the NDC per request:

	private static final AtomicLong requestCount = new AtomicLong(0L);

	public void doFilter(ServletRequest req, ServletResponse resp,
			FilterChain chain) throws ServletException, IOException {

		HttpServletRequest request = (HttpServletRequest) req;
		HttpServletResponse response = (HttpServletResponse) resp;

		// Retrieve the HttpSession. Create a new one if it does not exist.
		HttpSession session = request.getSession(true);
		String sessionId = session.getId();

		try {
			NDC.push(sessionId + ";" + requestCount.getAndIncrement());

			chain.doFilter(request, response);
		}
		finally {
			log.debug("Finished servicing request.");
			NDC.pop();
		}
	}



View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4056171#4056171

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4056171



More information about the jboss-user mailing list