在SpringBoot2.x.x版本之后,在application.yml配置文件中配置了修改默認logging.level(info)如下:
logging:
level: debug
然后報錯如下:
Caused by: org.springframework.boot.context.properties.bind.BindException: Failed to bind properties under 'logging.level' to java.util.Map<java.lang.String, org.springframework.boot.logging.LogLevel>
at org.springframework.boot.context.properties.bind.Binder.handleBindError(Binder.java:363)
at org.springframework.boot.context.properties.bind.Binder.bind(Binder.java:323)
at org.springframework.boot.context.properties.bind.Binder.bind(Binder.java:308)
at org.springframework.boot.context.properties.bind.Binder.bind(Binder.java:238)
at org.springframework.boot.context.properties.bind.Binder.bind(Binder.java:212)
at org.springframework.boot.context.logging.LoggingApplicationListener.setLogLevels
原因:在新版本中,logging.level后面需要指定對應的 “logger-name”,可以默認設置為root。
解決方法,修改成下面的形式:
logging:
level:
root: debug
具體解釋詳見官方文檔,官方文檔 https://docs.spring.io/spring-boot/docs/2.2.3.RELEASE/reference/htmlsingle/#boot-features-custom-log-levels,說明如下:
All the supported logging systems can have the logger levels set in the Spring Environment (for example, in application.properties) by using logging.level.<logger-name>=<level>where level is one of TRACE, DEBUG, INFO, WARN, ERROR, FATAL, or OFF. The root logger can be configured by using logging.level.root.
通過使用logging.level,所有支持的日志系統都可以在Spring環境(例如,在
application.properties)中設置日志程序級別。logging.level.<logger-name>=<level>,其中level是TRACE, DEBUG, INFO, WARN, ERROR, FATAL, or OFF其中一個,可以使用logging.level.root來配置root日志。
The following example shows potential logging settings in application.properties:
下面的示例顯示了application.properties中可能的日志記錄設置:
logging.level.root=warn
logging.level.org.springframework.web=debug
logging.level.org.hibernate=error
It’s also possible to set logging levels using environment variables. For example, LOGGING_LEVEL_ORG_SPRINGFRAMEWORK_WEB=DEBUG will set org.springframework.web to DEBUG.
還可以使用環境變量設置日志級別。例如,可以使用
LOGGING_LEVEL_ORG_SPRINGFRAMEWORK_WEB=DEBUGSPRINGFRAMEWORK_web設置org.springframework.web成DEBUG級別的。
The above approach will only work for package level logging. Since relaxed binding always converts environment variables to lowercase, it’s not possible to configure logging for an individual class in this way. If you need to configure logging for a class, you can use the SPRING_APPLICATION_JSON variable.
上面的方法只適用於包級水平的日志記錄。由於松散綁定總是將環境變量轉換為小寫,因此不可能以這種方式為單個類配置日志記錄。如果您需要為一個類配置日志記錄,您可以使用
SPRING_APPLICATION_JSON變量。
