繁体   English   中英

禁用 Spring boot websocket MessageBroker 日志的 INFO 级别日志记录

[英]Disable INFO level logging for Spring boot websocket MessageBroker logs

我有一个使用 SockJs 启用 Websocket 的 Spring Boot 应用程序。 一切正常,但它一直在控制台中记录以下消息。

2017-09-19 11:04:48.164  INFO 8856 --- [MessageBroker-4] o.s.w.s.c.WebSocketMessageBrokerStats    : WebSocketSession[1 current WS(1)-HttpStream(0)-HttpPoll(0), 3 total, 0 closed abnormally (0 connect failure, 0 send limit, 0 transport error)], stompSubProtocol[processed CONNECT(3)-CONNECTED(3)-DISCONNECT(0)], stompBrokerRelay[null], inboundChannel[pool size = 0, active threads = 0, queued tasks = 0, completed tasks = 45], outboundChannelpool size = 0, active threads = 0, queued tasks = 0, completed tasks = 22], sockJsScheduler[pool size = 4, active threads = 1, queued tasks = 2, completed tasks = 65909]

日志的意义是什么,我如何才能仅禁用这些类型的日志记录?

尝试在application.properties使用以下配置:

logging.level.org.springframework.web.socket.config.WebSocketMessageBrokerStats = ERROR

这将升级该特定类的日志。

我想根据@Dino 的评论改进这个答案,因为这个解决方案确实不显示日志,但它不会禁用任务,也不会阻止不必要的资源使用。

为了防止不必要的资源使用,请使用以下实现:

@Configuration
public class WebSocketLoggingConfigurer {

    @Autowired
    private WebSocketMessageBrokerStats webSocketMessageBrokerStats;

    @PostConstruct
    public void init() {
        webSocketMessageBrokerStats.setLoggingPeriod(0);
    }

}

现在没有必要使用application.properties修改日志级别。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM