记录 AsyncRequestTimeoutException 级别为“DEBUG”

问题描述 投票:0回答:1

Spring 框架的 DefaultHandlerExceptionResolver 处理 AsyncRequestTimeoutException 并打印以下几行。

2024-04-09 14:51:14.829  WARN 1 --- [qtp649630909-23] .w.s.m.s.DefaultHandlerExceptionResolver : Async request timed out
2024-04-09 17:18:38.786  WARN 28823 --- [tp2096524537-57] .w.s.m.s.DefaultHandlerExceptionResolver : Resolved [org.springframework.web.context.request.async.AsyncRequestTimeoutException]

如何将两条打印线设置为DEBUG?

附加信息:

  • 使用 org.slf4j 和 ch.qos.logback
java spring-boot spring-mvc logging
1个回答
0
投票

首先,找到 logback.xml 文件。该文件通常位于 Spring Boot 项目的 src/main/resources 目录中。如果该文件不存在,您可以创建它。

在 logback.xml 中,添加或修改配置以调整 DefaultHandlerExceptionResolver 的日志记录级别

<?xml version="1.0" encoding="UTF-8"?>
<configuration>

    <!-- Define loggers and appenders here -->
    
    <!-- Set the log level for DefaultHandlerExceptionResolver -->
    <logger name="org.springframework.web.servlet.mvc.method.annotation.DefaultHandlerExceptionResolver">
        <level value="DEBUG" />
    </logger>

    <!-- Set the log level for AsyncRequestTimeoutException -->
    <logger name="org.springframework.web.context.request.async.AsyncRequestTimeoutException">
        <level value="DEBUG" />
    </logger>

    <!-- Root logger configuration (if needed) -->
    <root level="INFO">
        <appender-ref ref="CONSOLE" />
    </root>

</configuration>

重新启动并再次测试

© www.soinside.com 2019 - 2024. All rights reserved.