spring boot war log4j2

2019-05-01 23:11发布

i'm developing a application using spring boot version 1.3.5 (spring 4.2.6). i use log4j2 version 2.4.1 as logging system. when working on sts (spring tool suite) and executing on embeeded tomcat, the logs works fine (on console and on file) but when building a war file and deploying it on external tomcat 8 the log file is created but my logs don't appear in it.

i've looked for similar issue and tested some solutions:

  1. setting the logging.config property on tomcat
  2. configuring 'application.properties' file with the parameter logging.config=classpath:log4j2-spring.xml
  3. using another logging framework (logback)

but none of this solution work. the post that talks about that is: Spring-Boot Logging configuration when deployed as .war

any help or detailled answer please.

1条回答
Deceive 欺骗
2楼-- · 2019-05-01 23:50

If you want to configure log4j for your Spring Boot application inside Tomcat, this documentation may help you :

https://tomcat.apache.org/tomcat-8.5-doc/logging.html#Using_Log4j

Using Log4j

This section explains how to configure Tomcat to use log4j rather than java.util.logging for all Tomcat's internal logging.

Note: The steps described in this section are needed when you want to reconfigure Tomcat to use Apache log4j for its own logging. These steps are not needed if you just want to use log4j in your own web application. — In that case, just put log4j.jar and log4j.properties into WEB-INF/lib and WEB-INF/classes of your web application.

The following steps describe configuring log4j to output Tomcat's internal logging.

Create a file called log4j.properties with the following content and save it into $CATALINA_BASE/lib

查看更多
登录 后发表回答