Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

spring boot war log4j2

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.

like image 813
idrmdi Avatar asked Jun 24 '16 11:06

idrmdi


People also ask

Does spring boot use log4j2?

Spring Boot also supports either Log4j or Log4j 2 for logging configuration, but only if one of them is on the classpath. If you are using the starter poms for assembling dependencies that means you have to exclude Logback and then include your chosen version of Log4j instead.

Is spring boot starter log4j2 affected?

Spring Boot users are only affected by this vulnerability if they have switched the default logging system to Log4J2. The log4j-to-slf4j and log4j-api jars that we include in spring-boot-starter-logging cannot be exploited on their own.

Does Tomcat use log4j2?

Log4j may be used as the logging framework for Apache Tomcat. This support is implemented automatically by including the log4j-api, log4j-core, and log4j-appserver jars in the boot classpath. A file named log4j2-tomcat.


1 Answers

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

like image 122
Mickael Avatar answered Nov 02 '22 11:11

Mickael