这个问题很简单,但我找不到资料。 (可能我对Java框架的知识严重缺乏)
如何使用application.properties设置日志级别? 日志文件的位置,等等?
这个问题很简单,但我找不到资料。 (可能我对Java框架的知识严重缺乏)
如何使用application.properties设置日志级别? 日志文件的位置,等等?
当前回答
确保Dave Syer技巧得到一些喜爱,因为向应用程序添加debug=true。属性确实会启用调试日志记录。
其他回答
更新:从Spring Boot v1.2.0开始。释放,应用程序中的设置。属性或应用程序。你可以。请参见参考指南的日志级别部分。
logging.level.org.springframework.web: DEBUG
logging.level.org.hibernate: ERROR
对于早期版本的Spring Boot,您不能这样做。为此,您只需使用日志框架的正常配置(log4j、logback)。将适当的配置文件(log4j.xml或logback.xml)添加到src/main/resources目录并根据自己的喜好进行配置。
当从命令行启动应用程序时,可以通过指定——debug来启用调试日志记录。
Spring Boot还为logback提供了一个很好的起点来配置一些默认值,着色等。base.xml文件可以简单地包含在你的logback.xml文件中。(这也是Spring Boot中默认的logback.xml的建议。
<include resource="org/springframework/boot/logging/logback/base.xml"/>
您可以尝试将日志级别设置为DEBUG,它将在启动应用程序时显示所有内容
logging.level.root=DEBUG
记录:官方文档,如Spring Boot v1.2.0。RELEASE和Spring v4.1.3 RELEASE:
If the only change you need to make to logging is to set the levels of various loggers then you can do that in application.properties using the "logging.level" prefix, e.g. logging.level.org.springframework.web: DEBUG logging.level.org.hibernate: ERROR You can also set the location of a file to log to (in addition to the console) using "logging.file". To configure the more fine-grained settings of a logging system you need to use the native configuration format supported by the LoggingSystem in question. By default Spring Boot picks up the native configuration from its default location for the system (e.g. classpath:logback.xml for Logback), but you can set the location of the config file using the "logging.config" property.
如果使用eclipse IDE,并且您的项目是maven,请记住清理并构建项目以反映更改。
在我当前的配置中,我在应用程序中定义了它。Yaml是这样的:
logging:
level:
ROOT: TRACE
我正在使用spring-boot:2.2.0.RELEASE。您可以像这样定义任何应该具有TRACE级别的包。