[jboss-user] [JBoss Seam] - Re: Using log4j's NDC
trautmane
do-not-reply at jboss.com
Tue Jul 3 18:27:37 EDT 2007
For what it is worth, here is what I'm currently using with Seam 1.2.1 to add the Seam identity username to the log4j mapped diagnostic context:
| @Startup
| @Scope(ScopeType.APPLICATION)
| @Name("some.package.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;
| String path = req.getServletPath();
| if ((path != null) && (path.endsWith(".seam"))) {
| 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);
| }
| }
|
You could do something similar with the NDC if you wanted.
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4060184#4060184
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4060184
More information about the jboss-user
mailing list