简体   繁体   English

Log4J2和Tomee Plus 7.0.47无法正常工作

[英]Log4J2 and Tomee Plus 7.0.47 not working

According to here , Log4j2 should work with Tomcat7.0.47. 根据这里 ,Log4j2应该与Tomcat7.0.47一起使用。 I'm using TomEE Plus 7.0.47. 我正在使用TomEE Plus 7.0.47。

I have a webapplication deployed with a log4j2.xml in my web-inf/classes folder. 我在web-inf / classes文件夹中部署了一个带log4j2.xml的Web应用程序。 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: 我在名称为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,并将以下库添加到tomcat库中:

  • slf4j-api-1.7.5.jar SLF4J-API-1.7.5.jar
  • log4j-api-2.0-rc1.jar 的log4j-API-2.0-rc1.jar
  • log4j-core-2.0-rc1.jar log4j的核-2.0-rc1.jar
  • log4j-slf4j-impl-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. 如果我将配置状态更改为TRACE,则可以看到我的配置文件被拾取,并且配置按预期进行。 Also I can see the MBeans being added. 我还可以看到正在添加MBean。 However, there's not one logging statement ending up in my logfile. 但是,在我的日志文件中没有结束的一条日志记录语句。 I debugged into the log4j2 Logger, and see that the isEnabled(...) method returns false because the logger (com.alex.util.JSON) has the level "ERROR" set, while the configuration set the package org.alex to TRACE. 我调试到log4j2 Logger中,发现isEnabled(...)方法返回false因为记录器(com.alex.util.JSON)的级别设置为“ ERROR”,而配置将包org.alex设置为跟踪。 Further investigation shows it uses a DefaultConfiguration configured for level=ERROR, and only root is configured. 进一步的调查显示,它使用为level = ERROR配置的DefaultConfiguration,并且仅配置了root。 I'm thinking of a classloader issue, but I can't seem to figure out what the cause is and how to solve it. 我正在考虑一个类加载器问题,但是我似乎无法弄清楚原因是什么以及如何解决它。 Does anyone know what I'm doing wrong? 有人知道我在做什么错吗?

This should work on trunk 这应该在树干上工作

Btw saw log4j2 has hacks for tomcat and since tomee wraps classloaders not sure they work as expected... 顺便说一句,log4j2拥有tomcat的黑客功能,并且由于tomee包装了类加载器,因此不确定它们是否按预期运行...

This is very strange. 这很奇怪。 Please raise a ticket for this in the Log4j2 issue tracker so the Log4j team can take a look. 请为此在Log4j2问题跟踪器中举票,以便Log4j团队查看。

The problem may go away if you put the jar files you mentioned inside WEB-INF/lib instead of in Tomcat's lib folder. 如果将您提到的jar文件放在WEB-INF / lib中而不是Tomcat的lib文件夹中,则问题可能会消失。

To be comple log4j2 relies on servletcontainerinitializer which are called after ejb and app scanning so ejbs can be loaded too early. 要进行编译,log4j2依赖servletcontainerinitializer,它在ejb和应用程序扫描之后被调用,因此ejb可能加载得太早。 Doing the same with a tomcat context listener would make it working better 用tomcat上下文监听器做同样的事情会使它更好地工作

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM