phenomenal logging to help others....
deanhiller2000 Jan 11, 2010 7:14 PMOur logs log the [session][username] if username exists(ie. user is logged in) on every log even the hibernate logs and log4jdbc logs and all third party logs AND most importantly on the exceptions in the seam logs so you know which user ran into the issue(or which session). This is the filter we use and I thought I would share...
package net.voicelog.entities.actions; import java.io.IOException; import javax.servlet.Filter; import javax.servlet.FilterChain; import javax.servlet.FilterConfig; import javax.servlet.ServletException; import javax.servlet.ServletRequest; import javax.servlet.ServletResponse; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpSession; import net.voicelog.ata.logging.LogKeyThreadLocal; public class FilterForLogging implements Filter { @Override public void destroy() { } @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain filter) throws IOException, ServletException { HttpServletRequest req = (HttpServletRequest) request; HttpSession session = req.getSession(); //let's reduce the session to make the logs easier int hashCode = session.getId().hashCode(); int result = hashCode / (Integer.MAX_VALUE / 1000); if(result < 0) result = -result; String key = "[session:"+result+"]"; if(session.getAttribute("user") != null) { Object user = session.getAttribute("user"); key += user; } LogKeyThreadLocal.setLogKey(key); filter.doFilter(request, response); } @Override public void init(FilterConfig arg0) throws ServletException { } }
NOTE: LogKeyThreadLocal stores the key in a Threadlocal that you can either have a Appender in log4j or a handler in jdk logging to read that and prefix the log with it so you know which user the log is tied to. This has been a HUGE help to us and it would be great if Seam added something like this as well and an appender and handler too that we could use and setup so everyone had this nice logging functionality. We should have a recorder as well later that records pages and actions the user takes so you can reproduce the issue in production that occurred.
later,
Dean