This content has been marked as final.
Show 3 replies
-
1. Re: How do I intercept or extend the seam logger?
pmuir Jun 3, 2008 10:53 PM (in response to kfletcher2005)Not possible AFAIK, but you could use something like a NDC/MDC with log4j.
-
2. Re: How do I intercept or extend the seam logger?
kfletcher2005 Jun 3, 2008 11:22 PM (in response to kfletcher2005)NDC/MDC with log4j looks promising. Thanks.
-
3. Re: How do I intercept or extend the seam logger?
kfletcher2005 Jun 4, 2008 8:49 PM (in response to kfletcher2005)The final solution looks like the LoggingFilter built into seam. You can add whatever you want to the MDC map from the request/session contexts.
@Scope(ScopeType.APPLICATION) @Name("yourLoggingFilter") @BypassInterceptors @Filter(within = "org.jboss.seam.web.authenticationFilter") @Install(classDependencies = "org.apache.log4j.Logger", dependencies = "org.jboss.seam.security.identity", precedence = Install.BUILT_IN) public class YourLoggingFilter extends AbstractFilter { public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException { HttpServletRequest req = ((HttpServletRequest) servletRequest); for(Cookie cookie :req.getCookies() ) { MDC.put(cookie.getName(), cookie.getValue() ); } HttpSession session = ((HttpServletRequest) servletRequest).getSession(false); if (session != null) { Object attribute = session.getAttribute("org.jboss.seam.security.identity"); if (attribute instanceof Identity) { Identity identity = (Identity) attribute; String username = identity.getUsername(); if (username != null) { /* * the log4j output conversion pattern looks like... * <param name="ConversionPattern" value="%d %-5r %-5p [%c] (%X{username} %X{remoteAddress}) %m%n"/> */ MDC.put("username", username); } } MDC.put("remoteAddress", servletRequest.getRemoteAddr()); MDC.put("whatever", "whatever"); MDC.put("locale", req.getLocale()); } filterChain.doFilter(servletRequest, servletResponse); /* * cleanup */ MDC.remove("username"); MDC.remove("remoteAddress"); MDC.remove("whatever"); MDC.remove("locale"); for(Cookie cookie :req.getCookies() ) { MDC.remove(cookie.getName() ); } } }