为 Spring 启动 websocket MessageBroker 日志禁用 INFO 级别日志记录
Disable INFO level logging for Spring boot websocket MessageBroker logs
我有一个 spring 启动应用程序,它启用了 Websocket 和 SockJs。一切正常,但它一直在控制台中记录以下消息。
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
这将升级此特定 class 的日志。
我想根据@Dino 的评论改进,因为这个解决方案确实不显示日志,但它不会禁用任务,也不会阻止不必要的资源使用。
为防止不必要的资源使用,请使用以下实现:
@Configuration
public class WebSocketLoggingConfigurer {
@Autowired
private WebSocketMessageBrokerStats webSocketMessageBrokerStats;
@PostConstruct
public void init() {
webSocketMessageBrokerStats.setLoggingPeriod(0);
}
}
现在不需要使用application.properties
修改日志级别。
我有一个 spring 启动应用程序,它启用了 Websocket 和 SockJs。一切正常,但它一直在控制台中记录以下消息。
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
这将升级此特定 class 的日志。
我想根据@Dino 的评论改进
为防止不必要的资源使用,请使用以下实现:
@Configuration
public class WebSocketLoggingConfigurer {
@Autowired
private WebSocketMessageBrokerStats webSocketMessageBrokerStats;
@PostConstruct
public void init() {
webSocketMessageBrokerStats.setLoggingPeriod(0);
}
}
现在不需要使用application.properties
修改日志级别。