Am 05.12.2016 um 08:32 schrieb frank.pien...@materna.de:
It's a little bit frustrating to configure Tomcat 8.5.8 with log4j2.
I put the following jars in $CATALINA_HOME/lib
        log4j 2 core (log4j-core-2.6.2.jar)
        log4j 2 api (log4j-api-2.6.2.jar)
Delete the file $CATALINA_HOME/conf/logging.properties
    Put the new log4j 2 config file (log4j2.xml) in $CATALINA_HOME/lib
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="warn" name="catalina" packages="">
    <Appenders>
         <Console name="console" target="SYSTEM_OUT">
    <PatternLayout pattern="%m%n"/>
        </Console>
            <File name="catalina" fileName="${catalina.base}/logs/catalina.log">
              <PatternLayout>
                <Pattern>%d %p %c{1.} [%t] %m%n</Pattern>
              </PatternLayout>
    </File>
        <Async name="Async">
              <AppenderRef ref="catalina"/>
       </Async>
    </Appenders>
      <Loggers>
        <Root level="trace">
          <AppenderRef ref="Async"/>
         <AppenderRef ref="console"/>
        </Root>
  </Loggers>
</Configuration>
No errors but the created catalina.out file is empty and the console layout 
doesn't change
What else to check or change?
THX Frank

Currently you need to put three log4j2 jar files into the CLASSPATH (not the lib directory):

- core
- api
- jul bridge

Next put your log4j2.xml in some special directory and add that directory to the CLASSPATH as well.

Since in 8.5 Log4J integration is via its jul bridge it must be loadable by jul, that's why CLASSPATH and not just the lib directory.

Finally add the following system property to inform jul that it should log via log4j2:

-Djava.util.logging.manager=org.apache.logging.log4j.jul.LogManager

for instance by setting LOGGING_MANAGER to that value. To reduce confusion I suggest to also set LOGGING_CONFIG to some dummy value, e.g. -Dnop.

See:

http://logging.apache.org/log4j/2.x/log4j-jul/index.html

There is a (minor) flaw currently in this integration: the location info (class name, method name, line number) will be wrong and always point to a fixed position in Tomcat Juli instead of the "real" class calling the log method.

For more details about this problem see also:

http://marc.info/?t=147740155100002&r=1&w=2

Regards,

Rainer

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org

Reply via email to