在application.yml中设置root日志记录级别

时间:2015-07-08 10:37:32

标签: java logging spring-boot yaml

我在Spring Boot(1.3 M1)中使用了application.properties并开始将其转换为yaml文件,因为它变得越来越复杂。

但是我将此翻译成yaml:

logging.level.*=WARN
logging.level.com.filenet.wcm=ERROR
logging.level.de.mycompany=DEBUG

最后两行很容易翻译成:

logging:
    level:
        com.filenet.wcm: ERROR
        de.mycompany: DEBUG

但是如何添加根日志记录级别的值?这两种方法都失败了:

方法1失败:

logging:
    level: WARN
        com.filenet.wcm: ERROR
        de.mycompany: DEBUG    

方法2失败:

logging:
    level: 
        star: WARN
        com.filenet.wcm: ERROR
        de.mycompany: DEBUG    

我读了docs,搜索了stackoverflow并用Google搜索,但没有找到有效语法的示例。

4 个答案:

答案 0 :(得分:94)

您可以使用ROOT配置根日志记录级别:

logging:
  level:
    ROOT: DEBUG

答案 1 :(得分:9)

如果要按包级别,则可以使用以下语法:

logging:
  level:
     org.springframework.web: DEBUG
     guru.springframework.controllers: DEBUG
     org.hibernate: DEBUG

答案 2 :(得分:1)

您甚至可以使用您的类名来配置日志记录级别:

logging:
  level:
    com.yourorganization.Yourclass: DEBUG

答案 3 :(得分:1)

这是一个古老的问题,但我只是遇到了这个问题。

同时设置

org.springframework.web: debug

org.hibernate: debug

工作正常,如果要对项目文件执行相同操作(每个程序包设置级别),则必须使用通配符。因此,对于问题中的示例,应为:

logging:
    level:
        root: WARN
        com.filenet.wcm.*: ERROR
        de.mycompany.*: DEBUG

或者,您可以不使用通配符来设置每个类的日志记录级别,如torina的答案所示。

相关问题