在所有级别的日志中,每个用户/会话有一个唯一的ID?Log4J?[英] A unique ID per User / Session in logs on all levels? Log4J?

本文是小编为大家收集整理的关于在所有级别的日志中,每个用户/会话有一个唯一的ID?Log4J?的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。

问题描述

好吧,我们正在进行一些性能测试,以找出应用程序的哪些步骤需要多少时间.当然,用RegexP易于解析/过滤器日志是一种魅力. 问题:我们的JSF应用程序分为几个项目,这些项目被其他(非JSF)应用程序使用. 我的第一种方法是:

if(logger.isDebugEnabled())
        logger.debug("Service call took: " + (System.currentTimeMillis() - time)+ " JSESSIONID="+CookieUtil.getJsessionId(FacesContext.getCurrentInstance())) ;

(cookieutil将从httpservletrequest读取sessionID)

但是...显然其他项目不喜欢JSF库的依赖性,也不喜欢我整洁的cookieutil. log4j是否提供东西? 有另一个工具/概念吗?

推荐答案

您可以完成您正在寻找的W/log4j MDC: log4j mdc

并使用类似于此示例类似的servlet过滤器: mdcservletfilter

本文地址:https://www.itbaoku.cn/post/1575114.html

问题描述

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?

推荐答案

You could accomplish what you are looking for w/ log4j MDC: Log4j MDC

and using a Servlet Filter similar to this example: MDCServletFilter