1

I am using log4j-api-2.0-beta4.jar along with sl4j in my web-app. I am trying to insert some values into ThreadContext.

ThreadContext.put("user",userName);           ThreadContext.put("thread",thread);
ThreadContext.put("url",url);

All I have done to get ThreadContext is to import the class.

At the end of the class, I am doing the following:

ThreadContext.clear();

The pattern layout that I am using in my log4j2.xml is:

<RollingFile name="Default" fileName="${logDir}/${filePrefix}.log"
                 filePattern="${logDir}/${filePrefix}/${filePrefix}.log.gz">
      <PatternLayout pattern="%d %-5p [%t] %37c %X{user} %x %m%n"/>
      <Policies>`enter code here`
        <SizeBasedTriggeringPolicy size="10MB"/>
      </Policies>
    </RollingFile>

I am not getting any value as part of %X{user} and %x gives me []. I need to get these values in my log file. Please help!!!

4

1 回答 1

0

好的。我自己想通了。

就是流程根本没有到达代码的那部分;)。

抱歉给大家添麻烦了,不过还是谢谢。

于 2013-05-22T11:08:12.447 回答