- 4 minutes to read

Enable Logging using Business Events

Log your messages from Mule with the Custom Business Event element for complete visibility and control.

Note

Custom Business Events are only available in Mule ESB Enterprise Edition

Tip

For even more advanced features, consider using the Nodinite Logging Custom Connector instead of Business Events.

Features

  • Events
    • Messages
    • Context Properties

Configuration

Always start your flows by initializing a session variable for reliable tracking and correlation.

runID
sessionvariable
Session variable initialization for runID in Mule ESB.

Review the Mule ESB Correlation user guide for additional information.

BusinessEventHandlerListener

To capture business events in the log file, add the following XML snippet in the Mule Flow before the <flow> element.

<!-- Custom Business Events to log -->
<spring:beans>
    <spring:bean class="se.integrationsoftware.integrationmanager.BusinessEventHandlerListener" id="notificationListener" />
</spring:beans>
<notifications>
    <notification-listener ref="notificationListener" />
</notifications>

CustomBusinessEvent_HandlerListener
BusinessEventHandlerListener configuration in Mule.

The class se.integrationsoftware.integrationmanager.BusinessEventHandlerListener must also be included in your project.

JavaPackage_Studio
Java package structure for the BusinessEventHandlerListener class.

package se.integrationsoftware.integrationmanager;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.mule.api.MuleContext;
import org.mule.api.context.MuleContextAware;
import com.mulesoft.mule.tracking.event.EventNotification;
import com.mulesoft.mule.tracking.event.EventNotificationListener;

public class BusinessEventHandlerListener implements EventNotificationListener<EventNotification>, MuleContextAware
{
	MuleContext context;

	protected static final Log logger = LogFactory.getLog("IMLog");
	
	@Override
	public void onNotification(EventNotification notification)
	{	
		String metaDatas = notification.getMetaDatas().toString();
		if (metaDatas != null)
		{
			if (metaDatas.startsWith("{"))
			{
				metaDatas = metaDatas.substring(1);
			}
			if (metaDatas.endsWith("}"))
			{
				metaDatas = metaDatas.substring(0, metaDatas.length() - 1);
			}
		}
		
		logger.info(metaDatas);
	}
	
	@Override
	public void setMuleContext(MuleContext context)
	{
		this.context = context;
	}
}

Mule ESB Flow - Custom Business Event element

Utilize the Custom Business Event element in the Mule Flow to log messages to Nodinite.

CustomBusinessEvent_Element
Custom Business Event element in Mule ESB.

Configure the Business Event element:

CustomBusinessEvent_Configuration
Configuration of the Custom Business Event element.

        <tracking:custom-event event-name="IMLog" doc:name="Custom Business Event">
            <tracking:meta-data key="im_logText" value="File received"/>
            <tracking:meta-data key="im_endPointName" value="File transfer business event receive"/>
            <tracking:meta-data key="im_endPointDirection" value="Receive"/>
            <tracking:meta-data key="im_messageContext" value="#[message]"/>
            <tracking:meta-data key="im_messageBody" value="#[message.payloadAs(java.lang.String)]"/>
        </tracking:custom-event>

Supported properties:

im_logText - informal text, Optional
im_endPointName - the Endpoint name, Mandatory
im_endPointDirection - the Endpoint direction, Valid values are: None, Unknown, Receive, Send, TwoWayReceive, TwoWaySend im_endPointTypeId - the Endpoint type id, Integer see below for valid codes, Optional
im_endPointUri - the Endpoint URI, Optional (overrides the Endpoint URI set by the log agent)
im_messageType - the Message Type, Optional
im_messageContext - the message context properties, #[message], Optional
im_messageContextCustom - a custom message context properties, key value pair of type <string,string> {"key1":"value1", "key2":"value2"} example {"transactionId":"FA0CAE5C-8968-44DF-836D-1DAA57D7831B","orderId":"1234"}, Optional
im_messageBody - the message payload, #[message.payloadAs(java.lang.String)], Optional
im_logStatusCode - the message status, Signed integer, Optional
im_integrationName -the name of the Integration. If this value is provided together with im_serviceName and/or im_contractName this Integration will be set for the Service and/or Contract, Optional
im_serviceName - the name of the Service. A Transport Contract is created with Message Type and Endpoint, if im_contractName is set only the Message Type will be set on the Transport Contract, Optional
im_serviceDirection - the direction of the Service, if not set the direction of the Endpoint will be used, Optional
im_serviceSystemName - the name of the System used for the Service, Optional
im_contractName - the name of the Contract. If this value is provided together with im_serviceName, the service will be set on the Contract, A Transport Contract is created with Message Type and Endpoint, Optional
im_contractSystemName - the name of the System used for the Contract, Optional

An event is logged to Nodinite if the mandatory properties exists.

Nodinite can extract the message type automatically from XML messages.

Log status code can be used to highlight errors, i.e. in a Mule exception handling element.

Exception information can be logged with
#[groovy:message.getExceptionPayload().getException().getCause()] and
#[groovy:message.getExceptionPayload().getException()]

EndpointTypeId

These codes are valid codes to be used with the im_endPointTypeId property:

See the list of Endpoint Types for available id:s to use


Next Step

Add or manage Log View
Add or manage Log Agents

Log Views
Log Agents
Install Mule Log Agent
Configuration of the agent