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

Gavin King (JIRA) jira-events at lists.jboss.org
Fri Jul 6 16:36:52 EDT 2007


     [ http://jira.jboss.com/jira/browse/JBSEAM-1610?page=all ]

Gavin King closed JBSEAM-1610.
------------------------------

    Fix Version/s: 2.0.0.CR1
       Resolution: Done
         Assignee: Gavin King

Thanks, applied this :-)

> 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
>         Assigned To: Gavin King
>             Fix For: 2.0.0.CR1
>
>
> 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