Operator log()
为方便起见,为了记录消息通过 Spring Integration 流的行程(<logging-channel-adapter>
),提供了一个 log()
运算符。在内部,它由 WireTap
ChannelInterceptor
表示,其订阅者是 LoggingHandler
。它负责将传入消息记录到下一个端点或当前通道。以下示例展示了如何使用 LoggingHandler
:
For convenience, to log the message journey through the Spring Integration flow (<logging-channel-adapter>
), a log()
operator is presented.
Internally, it is represented by the WireTap
ChannelInterceptor
with a LoggingHandler
as its subscriber.
It is responsible for logging the incoming message into the next endpoint or the current channel.
The following example shows how to use LoggingHandler
:
.filter(...)
.log(LoggingHandler.Level.ERROR, "test.category", m -> m.getHeaders().getId())
.route(...)
在前面的示例中,一个 id
头在仅针对通过筛选器且在路由之前的消息的 ERROR
级别上记录到 test.category
。
In the preceding example, an id
header is logged at the ERROR
level onto test.category
only for messages that passed the filter and before routing.
从 6.0 版开始,此运算符在流结束时的行为与其在中间时的用法保持一致。换句话说,即使移除了 log()
运算符,流的行为仍然保持不变。因此,如果流结束时预期不产生回复,则建议在最后一个 log()
之后使用 nullChannel()
。
Starting with version 6.0, the behavior of this operator in the end of flow is aligned with its usage in the middle.
In other words the behavior of the flow remains the same even if the log()
operator is removed.
So, if a reply is not expected to be produced in the end of the flow, the nullChannel()
is recommended to be used after the last log()
.