A unique ID per User / Session in logs on all levels? Log4J?

佐手、 提交于 2019-12-12 23:53:03

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!