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

查看:521
本文介绍了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.propertiesapplication.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还提供了一个不错的起点,可以用于登录以配置一些默认值,着色等.base.xml 文件,您只需将其包含在logback.xml文件中即可. (也建议从默认的logback.xml 在Spring Boot中.

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天全站免登陆