Spring Boot嵌入式tomcat日志 [英] Spring boot embedded tomcat logs

查看:341
本文介绍了Spring Boot嵌入式tomcat日志的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用带有Spring Boot 1.5.9的spring boot嵌入式tomcat, 我还使用Log4j2.

i'm using spring boot embedded tomcat with spring boot 1.5.9 , im also using Log4j2.

最近我在加载过程中遇到了问题,所以我想更好地了解tomcat日志[不是访问日志],我尝试过(在application.properties中):

recently i exerience problems during load, so i want to understand better the tomcat logs [Not the access Logs] , i tried (in application.properties) :

logging.level.org.apache.tomcat: INFO
logging.level.org.apache.catalina: INFO

但以上方法均无效.还有其他方法可以实现吗?

but none of the above worked. is there any other way to achieve it ?

推荐答案

找到了!现在,您可以通过3个简单的步骤在应用程序的Log4j日志文件中查看Embedded Tomcat的内部日志:

Found it !! You are now able to see the internal Logs of Embedded Tomcat in your App's Log4j log file with 3 easy steps:

1]添加到您的pom:

1] add to your pom:

 <dependency>
      <groupId>org.apache.logging.log4j</groupId>
      <artifactId>log4j-jul</artifactId>
     </dependency>

2]向运行中的arg添加一个新的JVM参数,例如:

2] add to your running arg a new JVM param , e.g:

java -Djava.util.logging.manager=org.apache.logging.log4j.jul.LogManager -jar target/demo-0.0.1-SNAPSHOT.jar

3]添加到您的application.properties:

3] add to your application.properties:

logging.level.org.apache=DEBUG

享受生活! :)

说明: 问题是因为Log4j日志级别没有传播到JUL中(这是嵌入式tomcat实际使用的日志记录方式),因此以上内容实现了与JUL和Log4j日志级别的这种连接.

Explaination: the problem is because Log4j log levels is not propagated into JUL (which is the actual Logging way Embedded tomcat use) so the above achieves this connection with JUL and Log4j log levels.

参考: 阅读了Spring boot 1.5.10发行说明(该解决方案不是必需的)之后,我看到了新的文档,阐明了如何实现它并对其进行解释:

Reference: After reading the Spring boot 1.5.10 release notes (which is not required for the solution) i saw the new documentation that shed light how to achive it and explaination about it:

https://github.com/spring-projects/spring-boot/issues/2923#issuecomment-358451260

这篇关于Spring Boot嵌入式tomcat日志的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆