How to set the logging level of embedded tomcat in

2019-05-10 22:29发布

How to set the logging level of embedded tomcat in Spring Boot?

Especially I need to see the tomcat clustering-related logs.

I added the following line to the application.properties, but tomcat seems to log only INFO level logs.

logging.level.org.apache.catalina=TRACE

Is there a simple method to accomplish this?

It would be best to know the Spring Boot and embedded tomcat-specific, simple solution, preferably only editing application.properties.

1条回答
干净又极端
2楼-- · 2019-05-10 23:12

In short, use Spring Boot version 1.3.0 with Logback. (I was using Spring Boot 1.2.4)

Spring Boot 1.3.0 adds LevelChangePropagator to LogbackLoggingSystem.java (see this commit), thus the logging level that is set in application.properties is propagated to the jul(java.util.logging) which tomcat uses.

Otherwise, one must set the logging level for the logger in the logging.properties for the jul if the level is below the INFO level which is the default, AND also set the logging level for the logger in the application.properties. This is for the limitation of jul-to-slf4j module which cannot completely override jul implementation since jul is in the java.* package.

Also see the following Spring Boot issues: Optimize JUL logging #2585, Slf4JLoggingSystem should also configure JUL levels #2923.

And this is the related StackOverflow question: Spring Boot - set logging level of external jar which is using Java Util Logging (jul). Actually this is the problem I was facing.

(I will accept this answer if no better answer is posted for a few days from now.)

查看更多
登录 后发表回答