无法使用 Spring Boot Actuator 更改日志级别

发布于 2025-01-11 21:34:00 字数 760 浏览 3 评论 0原文

我有两个现有的 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.xmlorg.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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

败给现实 2025-01-18 21:34:00

我的团队领导帮助确定了这个问题。 log4j2-spring.xml 有多个具有多个自定义级别的文件附加程序,类似于下面列出的用于各种目的(例如审核、备份、拒绝等)的内容。

    <Loggers>
        <Root level="WARN">
            <AppenderRef ref="Console" />
            <AppenderRef ref="defaultLogFile" level="info"/>
            <AppenderRef ref="MyAppAuditFile" level="auditLevel" />
            <AppenderRef ref="MyAppReplayFile" level="replayLevel" />
            <AppenderRef ref="MyAppBackupFile" level="backupLevel"/>
        </Root>
    </Loggers>

可以看出,默认日志文件的日志级别设置为 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.

    <Loggers>
        <Root level="WARN">
            <AppenderRef ref="Console" />
            <AppenderRef ref="defaultLogFile" level="info"/>
            <AppenderRef ref="MyAppAuditFile" level="auditLevel" />
            <AppenderRef ref="MyAppReplayFile" level="replayLevel" />
            <AppenderRef ref="MyAppBackupFile" level="backupLevel"/>
        </Root>
    </Loggers>

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文