Java 在 application.yml 中设置根日志记录级别
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/31290204/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Set root logging level in application.yml
提问by Marged
I used an application.properties with Spring Boot (1.3 M1) and started to translate it into a yaml file because it grew more and more complex.
我在 Spring Boot (1.3 M1) 中使用了 application.properties 并开始将其转换为 yaml 文件,因为它变得越来越复杂。
But I have problems translating this into yaml:
但是我在将其转换为 yaml 时遇到了问题:
logging.level.*=WARN
logging.level.com.filenet.wcm=ERROR
logging.level.de.mycompany=DEBUG
The last two lines are easily translated into this:
最后两行很容易翻译成这样:
logging:
level:
com.filenet.wcm: ERROR
de.mycompany: DEBUG
But how to add the values for the root logging level ? These two approaches failed:
但是如何添加根日志级别的值呢?这两种方法都失败了:
Failed approach 1:
失败的方法1:
logging:
level: WARN
com.filenet.wcm: ERROR
de.mycompany: DEBUG
Failed approach 2:
失败的方法2:
logging:
level:
star: WARN
com.filenet.wcm: ERROR
de.mycompany: DEBUG
I read the docs, searched stackoverflow and googled but did not find an example for a valid syntax.
我阅读了文档,搜索了 stackoverflow 并用谷歌搜索,但没有找到有效语法的示例。
采纳答案by Andy Wilkinson
You can use ROOT
to configure the root logging level:
您可以使用ROOT
来配置根日志记录级别:
logging:
level:
ROOT: DEBUG
回答by Michael COLL
If you want level by package, you can use this syntax :
如果你想逐个包,你可以使用这个语法:
logging:
level:
org.springframework.web: DEBUG
guru.springframework.controllers: DEBUG
org.hibernate: DEBUG
org: INFO
回答by torina
You can even use your classnameto configure logging level:
您甚至可以使用您的类名来配置日志记录级别:
logging:
level:
com.yourorganization.Yourclass: DEBUG
回答by Joakim
It's an old question, but I just had this problem.
这是一个老问题,但我刚刚遇到了这个问题。
While setting
设置时
org.springframework.web: debug
or
或者
org.hibernate: debug
works fine, if you want to do the same for your project files (setting level per package), you have to use wildcards. So, for the example in the question, it would be:
工作正常,如果你想对你的项目文件做同样的事情(设置每个包的级别),你必须使用通配符。因此,对于问题中的示例,它将是:
logging:
level:
root: WARN
com.filenet.wcm.*: ERROR
de.mycompany.*: DEBUG
Alternatively, you can set the logging level per class without using wildcards, as shown in torina's answer.
或者,您可以在不使用通配符的情况下设置每个类的日志记录级别,如 torina 的回答所示。