You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Spring Boot开启TRACE模式时如何屏蔽NioEndpoint重复日志?

解决Spring Boot中NioEndpoint重复DEBUG日志刷屏问题

你遇到的问题大概率是配置格式错误或者日志框架优先级导致的,以下是可行的解决方法:

1. 修正application.properties/yml配置格式

首先检查你的配置项是否有多余空格——你之前的配置里org.apache.tomcat.util.net.NioEndpoint =INFO包含空格,这会导致Spring无法正确识别该配置键。

正确的配置如下:

application.properties

# 全局开启TRACE级别
logging.level.root=TRACE
# 单独将NioEndpoint设为INFO级别,屏蔽其DEBUG日志
logging.level.org.apache.tomcat.util.net.NioEndpoint=INFO

application.yml

logging:
  level:
    root: TRACE
    org.apache.tomcat.util.net.NioEndpoint: INFO

2. 自定义Logback配置(若全局TRACE覆盖包级别配置)

如果上述配置仍未生效,可能是全局TRACE级别覆盖了包级别的配置,此时需要自定义Logback配置文件logback-spring.xml,明确指定NioEndpoint的日志级别并禁用日志传递:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <!-- 控制台输出配置 -->
    <appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
        <encoder>
            <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
        </encoder>
    </appender>

    <!-- 单独配置NioEndpoint的日志级别,additivity=false避免被root日志重复处理 -->
    <logger name="org.apache.tomcat.util.net.NioEndpoint" level="INFO" additivity="false">
        <appender-ref ref="CONSOLE"/>
    </logger>

    <!-- 全局TRACE级别 -->
    <root level="TRACE">
        <appender-ref ref="CONSOLE"/>
    </root>
</configuration>

将该文件放在src/main/resources目录下,Spring Boot会自动加载。

3. 若使用Log4j2日志框架

如果你的项目引入了Log4j2依赖(而非默认的Logback),配置方式如下:

application.properties

logging.level.root=TRACE
logging.log4j2.level.org.apache.tomcat.util.net.NioEndpoint=INFO

或者自定义log4j2.xml配置文件:

<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN">
    <Appenders>
        <Console name="Console" target="SYSTEM_OUT">
            <PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
        </Console>
    </Appenders>
    <Loggers>
        <Logger name="org.apache.tomcat.util.net.NioEndpoint" level="INFO" additivity="false">
            <AppenderRef ref="Console"/>
        </Logger>
        <Root level="TRACE">
            <AppenderRef ref="Console"/>
        </Root>
    </Loggers>
</Configuration>

额外检查点

  • 确认配置文件没有拼写错误,包路径org.apache.tomcat.util.net.NioEndpoint必须完全正确。
  • 重启应用,确保新配置生效(IDE运行时可能存在缓存,建议清理后重启)。
  • 检查是否有其他日志配置文件(如logback.xml、log4j2.xml)覆盖了application中的配置。

内容的提问来源于stack exchange,提问作者JavaSheriff

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.14 09:40:09