简体   繁体   English

Log4j2 不记录部署在 tomcat 中的应用程序

[英]Log4j2 not logging for application deployed in tomcat

Tomcat version: 8.0.30 Tomcat 版本:8.0.30

I have a Java application that uses Log4j2 deployed in Tomcat 8 on Linux (Centos 7), and for some reason, nothing is being written to the application logs.我有一个 Java 应用程序,它使用部署在 Linux (Centos 7) 上的 Tomcat 8 中的 Log4j2,由于某种原因,应用程序日志中没有写入任何内容。 I know however that my configuration should work, because it works perfectly on a different server.但是我知道我的配置应该可以工作,因为它可以在不同的服务器上完美运行。

The only difference I've noticed between the server that works and the one that doesn't is that in catalina.out on server start, I see the following warning on the server that doesn't work:我注意到的服务器之间的唯一区别是在服务器启动时的catalina.out ,我在无法工作的服务器上看到以下警告:

log4j:WARN No appenders could be found for logger (org.springframework.web.context.support.StandardServletEnvironment). 

I've tried researching this issue but haven't been able to resolve that warning.我曾尝试研究此问题,但无法解决该警告。

Not sure if this matters (because this works on other servers), but I have the following log4j2 dependencies in my pom.xml:不确定这是否重要(因为这适用于其他服务器),但我的 pom.xml 中有以下 log4j2 依赖项:

  • log4j-api log4j-api
  • log4j-core log4j-核心
  • log4j-1.2-api log4j-1.2-api
  • log4j-jcl log4j-jcl
  • log4j-slf4j-impl log4j-slf4j-impl

The warning you mentioned means that somewhere in app there is a old dependency log4j 1.2 and application is looking for old log4j.xml config file.您提到的警告意味着应用程序中的某个地方存在旧的依赖关系 log4j 1.2 并且应用程序正在寻找旧的 log4j.xml 配置文件。

First of all try to add log4j-api-2.x depencency which is the bridge between old log4j 1.2 version and log4j2 and redirects all logs from log4j 1.2 to log4j2.首先尝试添加 log4j-api-2.x 依赖,它是旧 log4j 1.2 版本和 log4j2 之间的桥梁,并将所有日志从 log4j 1.2 重定向到 log4j2。 Thi page helped me a lot: link to understand it.这个页面帮了我很多:链接来理解它。

If it will not help try to check dependency tree and exclude older log4j dependencies.如果它没有帮助,请尝试检查依赖关系树并排除旧的 log4j 依赖关系。 Also check if your tomact on linux has any other logging implementations than log4j2 and remove that libs.还要检查你的 linux 上的 tomact 是否有除 log4j2 之外的任何其他日志记录实现并删除该库。 Maybe the libs are different between your tomcats.也许你的 tomcat 之间的库是不同的。

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

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