Uploaded image for project: 'Log4j 2'
  1. Log4j 2
  2. LOG4J2-575

Log4J2 and Tomee Plus 7.0.47 not working

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Major
    • Resolution: Unresolved
    • 2.0-rc1
    • None
    • Core

    Description

      According to http://logging.apache.org/log4j/2.x/manual/webapp.html, Log4j2 should work with Tomcat7.0.47. I'm using TomEE Plus 7.0.47.

      I have a webapplication deployed with a log4j2.xml in my web-inf/classes folder. This is the config:

          <?xml version="1.0" encoding="UTF-8"?>
          <Configuration status="WARN">
          <Appenders>
              <Console name="Console" target="SYSTEM_OUT">
                  <PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
              </Console>
              <File name="File" fileName="${sys:catalina.home}/logs/testapp.log">
                  <PatternLayout>
                      <pattern>%d %p %C{1.} [%t] %m%n</pattern>
                  </PatternLayout>
              </File>
          </Appenders>
          <Loggers>
              <Logger name="org.alex" level="TRACE" additivity="false">
                  <AppenderRef ref="File"/>
              </Logger>
              <Root level="INFO">
                  <AppenderRef ref="Console"/>
              </Root>
          </Loggers>
          </Configuration>
      
      

      I have a logger declared in a class with name org.alex.util.JSON:

      private static final Logger LOG = LoggerFactory.getLogger(JSON.class);

      I'm using slf4j-api 1.7.5, and have the following libs added to the tomcat lib:

      slf4j-api-1.7.5.jar
      log4j-api-2.0-rc1.jar
      log4j-core-2.0-rc1.jar
      log4j-slf4j-impl-2.0-rc1.jar

      If I change the Configuration status to TRACE, I can see my configuration file being picked up and configuration happens as expected. Also I can see the MBeans being added.
      However, there's not one logging statement ending up in my logfile (although the file is created). I debugged into the log4j2 Logger, and see that the isEnabled(...) method return false because the logger (com.alex.util.JSON) has the level "ERROR" set, while the configuration set the package org.alex to TRACE.
      Further investigation shows it uses a DefaultConfiguration configured for level=ERROR, and only root is configured.

      Furthermore I noticed that the classloader for the instance of my logger that is created at configuration is org.apache.openejb.core.TempClassLoader, while the classloader of the Logger that is invoked is org.apache.catalina.loader.StandardClassLoader. I don't know enough of the whole mechanism to judge whether or not this is to be expected

      Attachments

        Activity

          People

            Unassigned Unassigned
            AlexGout Alex Gout
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated: