Spring Boot:如何使用 application.properties 设置日志记录级别? [英] Spring Boot: How can I set the logging level with application.properties?

查看:51
本文介绍了Spring Boot:如何使用 application.properties 设置日志记录级别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个很简单的问题,但我找不到信息.
(也许我对 Java 框架的了解严重缺乏)

This is very simple question, but I cannot find information.
(Maybe my knowledge about Java frameworks is severely lacking)

如何使用 application.properties 设置日志记录级别?
以及日志文件位置等?

How can I set the logging level with application.properties?
And logging file location, etc?

推荐答案

更新: 从 Spring Boot v1.2.0.RELEASE 开始,application.properties 中的设置或application.yml 确实适用.请参阅 参考指南的日志级别部分.

Update: Starting with Spring Boot v1.2.0.RELEASE, the settings in application.properties or application.yml do apply. See the Log Levels section of the reference guide.

logging.level.org.springframework.web: DEBUG
logging.level.org.hibernate: ERROR

对于早期版本的 Spring Boot,你不能.为此,您只需使用日志框架(log4j、logback)的正常配置.将适当的配置文件(log4j.xmllogback.xml)添加到 src/main/resources 目录并根据您的喜好进行配置.

For earlier versions of Spring Boot you cannot. You simply have to use the normal configuration for your logging framework (log4j, logback) for that. Add the appropriate config file (log4j.xml or logback.xml) to the src/main/resources directory and configure to your liking.

您可以通过在从命令行启动应用程序时指定 --debug 来启用调试日志记录.

You can enable debug logging by specifying --debug when starting the application from the command-line.

Spring Boot 也为 logback 提供了一个很好的起点来配置一些默认值、着色等. base.xml 文件,您可以简单地将其包含在 logback.xml 文件中.(这也是从默认的 logback.xml.

Spring Boot provides also a nice starting point for logback to configure some defaults, coloring etc. the base.xml file which you can simply include in your logback.xml file. (This is also recommended from the default logback.xml in Spring Boot.

<include resource="org/springframework/boot/logging/logback/base.xml"/>     

这篇关于Spring Boot:如何使用 application.properties 设置日志记录级别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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