<flow> <inbound-endpoint ref="myInboundEndpoint" /> <logger message="Hello from my Flow!" /></flow>
Logger Element for Flows
Mule has always supported flows with <log-component>, but as of Mule 3.1, a new implementation called <logger> has been baked into the message processor for use anywhere within a flow.
Where Can <logger> Be Used?
-
Anywhere in a <flow>
-
Within inbound and outbound endpoint elements (or within their optional <response> elements)
-
Within the <inbound> section of a <service> after the endpoints
-
Within the <asynch-reply> section of a <service> after the endpoints
How Do I Use <logger> at a Certain Point in a Flow or a Service?
Add <logger> at the point where you want to log the message:
This will log the message specified using the default DEBUG level, so you will see this in your log only if you have your log level set at DEBUG or TRACE level.
How Does <logger> Work Using WARN/ERROR?
Add the 'level' attribute. An XML editor should show you the permissible values: ERROR, WARN, INFO, DEBUG and TRACE.
This example uses the a wire tap configured with an expression filter to log our message using the ERROR category only when the incoming payload does not contain a certain string.
<flow> <inbound-endpoint ref="myInboundEndpoint" /> <wiretap> <logger message="Ooops we have an invalid message!" level="ERROR" /> <expression-filter evaluator="groovy" expression="!payload.contains('valid message')" /> </wiretap></flow>
How Can I Log the Entire Message Payload?
In order to log your message payload, headers, the whole message or a single value from within your payload, <logger> leverages Mule Expressions. Rather than specifying a single expression for logging you can embed as many expressions as you required in your log ‘message’ as required. This allows you to give some context to what is being logged, and enables you to log multiple things at once.
<flow> <inbound-endpoint ref="myInboundEndpoint" /> <wiretap> <logger message="Ooops! #[payload] is an invalid message!" level="ERROR" /> <expression-filter evaluator="groovy" expression="!payload.contains('valid message')" /> </wiretap></flow>