我希望spring只记录以下代码行:
this.logger.debug("New connection " + this.getConnectionId());
因此我在application.properties
中添加了以下配置:
logging.level.org.springframework.integration.ip.tcp.connection.TcpNioConnection=DEBUG
这样可以正常工作,但当然它会记录该类中的任何logger.debug()
语句。
问题:是否可以仅记录所需的声明?
答案 0 :(得分:0)
解决它听取套接字事件:
@Component
public class SocketListener {
private final Logger LOGGER = LoggerFactory.getLogger(this.getClass());
@EventListener
public void onTcpConnectionOpenEvent(TcpConnectionOpenEvent event) {
LOGGER.info("new con " + event.getConnectionId());
}
@EventListener
public void onTcpConnectionCloseEvent(TcpConnectionCloseEvent event) {
LOGGER.info("con closed " + event.getConnectionId());
}
@EventListener
public void onTcpConnectionOpenEvent(TcpConnectionExceptionEvent event) {
LOGGER. error("con error " + event.getConnectionId());
}
}