简体   繁体   中英

Log4j2 not logging for application deployed in tomcat

Tomcat version: 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. 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:

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:

  • log4j-api
  • log4j-core
  • log4j-1.2-api
  • log4j-jcl
  • 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.

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. 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. Also check if your tomact on linux has any other logging implementations than log4j2 and remove that libs. Maybe the libs are different between your tomcats.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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