问题
Well we are doing some performance testing to figure out what steps of our application take how much time. Of course easy to parse / filter logs with regexp are a charm. To the problem: Our jsf application is split into several projects, which are used by other (non jsf) applications. My first approach would have been:
if(logger.isDebugEnabled())
logger.debug("Service call took: " + (System.currentTimeMillis() - time)+ " JSESSIONID="+CookieUtil.getJsessionId(FacesContext.getCurrentInstance())) ;
(CookieUtil would read the sessionId from the HttpServletRequest)
But... obviously other projects don't like dependencies to JSF libraries, nor to my neat CookieUtil. Does log4j provide something? Is there another tool / concept for this?
回答1:
You could accomplish what you are looking for w/ log4j MDC: Log4j MDC
and using a Servlet Filter similar to this example: MDCServletFilter
来源:https://stackoverflow.com/questions/5901347/a-unique-id-per-user-session-in-logs-on-all-levels-log4j