[jbossseam-issues] [JBoss JIRA] Created: (JBSEAM-1610) Add log4j diagnostic context filter to Seam logging package

Eric Trautman (JIRA) jira-events at lists.jboss.org
Thu Jul 5 16:42:52 EDT 2007


Add log4j diagnostic context filter to Seam logging package
-----------------------------------------------------------

                 Key: JBSEAM-1610
                 URL: http://jira.jboss.com/jira/browse/JBSEAM-1610
             Project: JBoss Seam
          Issue Type: Feature Request
          Components: Core
    Affects Versions: 2.0.0.BETA1
            Reporter: Eric Trautman


Consider adding a web filter that populates the log4j mapped diagnostic context with the identity username.

Thanks,
Eric Trautman

Here is an example of what I am currently using:

/**
 * This filter adds the authenticated user name to the log4j
 * mapped diagnostic context so that it can be included in
 * formatted log output if desired.
 */
@Startup
@Scope(ScopeType.APPLICATION)
@Name("org.jboss.seam.web.loggingContextFilter")
@Intercept(InterceptionType.NEVER)
@Install
public class LoggingContextFilter extends AbstractFilter {

    /** Identifier for the username "diagnostic context". */
    public static final String USERNAME_CONTEXT = "username";

    public void doFilter(ServletRequest servletRequest,
                         ServletResponse servletResponse,
                         FilterChain filterChain)
            throws IOException, ServletException {

        if (servletRequest instanceof HttpServletRequest) {

            HttpServletRequest req = (HttpServletRequest) servletRequest;
            if (matchesRequestPath(req)) {
                HttpSession session = req.getSession();
                Object o = session.getAttribute("org.jboss.seam.security.identity");
                if (o instanceof Identity) {
                    Identity identity = (Identity) o;
                    String username = identity.getUsername();
                    if (username != null) {
                        MDC.put(USERNAME_CONTEXT, username);
                    }
                }
            }
        }

        filterChain.doFilter(servletRequest, servletResponse);

        MDC.remove(USERNAME_CONTEXT);
    }
}

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://jira.jboss.com/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        



More information about the seam-issues mailing list