如需使用最新稳定版本,请使用 Spring Integration 7.0.4spring-doc.cadn.net.cn

操作符 log()

为了方便记录消息在 Spring Integration 流程(<logging-channel-adapter>)中的流转,系统提供了一个 log() 算子。 在内部,它由一个以 LoggingHandler 作为订阅者的 WireTap ChannelInterceptor 表示。 其职责是将传入的消息记录到下一个端点或当前通道中。 以下示例展示了如何使用 LoggingHandlerspring-doc.cadn.net.cn

.filter(...)
.log(LoggingHandler.Level.ERROR, "test.category", m -> m.getHeaders().getId())
.route(...)

在前面的示例中,仅针对通过过滤器并在路由之前的消息,id 级别的标头会被记录到 ERRORtest.category 上。spring-doc.cadn.net.cn

从版本 6.0 开始,该操作符在流程末尾的行为已与其在中间的使用方式保持一致。 换句话说,即使移除了 log() 操作符,流程的行为也保持不变。 因此,如果预期在流程末尾不产生回复,建议在最后一个 log() 之后使用 nullChannel()spring-doc.cadn.net.cn