无法使用 Spring Boot Actuator 更改日志级别
我有两个现有的 Spring Boot 应用程序,其中为记录器启用了执行器端点。
两者都有 Gradle 规则和 application.properties 条目,如下所示。
compile('org.springframework.boot:spring-boot-starter-actuator')
management.endpoints.web.exposure.include=env,loggers
management.endpoint.loggers.enabled=true
但是,当我尝试如下更改日志级别时,它仅适用于第一个应用程序。
curl -s -X POST -H 'Content-Type: application/json' -d '{"configuredLevel": "debug"}' http://localhost:8080/actuator/loggers/com.zzz.yyy.ddd
我没有外部化记录器配置文件(即它们位于两个应用程序的 src/main/resources 中)。 经过一番挖掘,发现第一个应用程序将 logback.xml
与 SL4J 记录器一起使用,而第二个应用程序将 log4j2-spring.xml
与 org.apache 一起使用。日志记录器。这可能是原因吗?我们是否必须使用 logback/SL4J 来使执行器端点工作的日志级别发生变化?
I have two existing Spring Boot Applications with actuator endpoints enabled for loggers.
Both have Gradle rule and application.properties entries as below.
compile('org.springframework.boot:spring-boot-starter-actuator')
management.endpoints.web.exposure.include=env,loggers
management.endpoint.loggers.enabled=true
But, when I try change log level as below it is working only for first app.
curl -s -X POST -H 'Content-Type: application/json' -d '{"configuredLevel": "debug"}' http://localhost:8080/actuator/loggers/com.zzz.yyy.ddd
I am not externalizing logger config files (i.e. they are in src/main/resources
for both apps).
After some digging noticed that the first app is using logback.xml
with SL4J logger, where as second app is using log4j2-spring.xml
with org.apache.logging.logger
. Could that be the reason and is it that we have to use logback/SL4J to make log level change with actuator endpoint work?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我的团队领导帮助确定了这个问题。
log4j2-spring.xml
有多个具有多个自定义级别的文件附加程序,类似于下面列出的用于各种目的(例如审核、备份、拒绝等)的内容。可以看出,默认日志文件的日志级别设置为 info因此,只有信息和更高级别的信息才会进入该文件,因此当日志级别更改为调试时,这些调试消息永远不会进入日志文件。由于控制台没有日志级别设置,导致调试消息显示在 IDE 中。因此,修复方法是删除默认日志文件的
level
条目,就像 Console 一样。My team lead helped identify the issue.
log4j2-spring.xml
had multiple file appenders with multiple custom levels, similar to listed below for various purpose like audit, backup, rejects etc.As can be seen the default log file had log level set as info and hence only info and higher are going to that file, so when log level is changed to debug, those debug messages never went to log file. Where as Console didn't 've a log level setting resulting in debug messages to be displayed in IDE. So the fix was to just remove the
level
entry for default log fie just like Console.