Contact Us 1-800-596-4880

Logger Component Reference

Mule Runtime Engine versions 3.5, 3.6, and 3.7 reached End of Life on or before January 25, 2020. For more information, contact your Customer Success Manager to determine how you can migrate to the latest Mule version.

Use the Logger to log messages such as error messages, status notifications, or exceptions. You can add a logger anywhere in a flow, and you can configure it to log anything: any string, any Mule expression, or any combination of strings and Mule expressions.

Configuration

STUDIO Visual Editor

logger
Field Value Description Example XML

Display Name

Logger

Customize to display a unique name for the logger in your application.

doc:name="Logger"

Message

String or Mule expression

Specify what Mule should log. By default, messages are logged to the console in Mule Studio.

message="Current payload is #[payload]"

Level

Select a level from the listed options:

  • ERROR

  • WARN

  • INFO

  • DEBUG

  • TRACE

Specify the level at which the message should be logged.

You can create this file automatically through Studio by right-clicking on your project in the package explorer, and selecting Mule > Create Log4j Configuration. Then you can find a log4j2.xml file in your project’s src/main/resources folder and edit it through Studio.

level="INFO"

Category

Optional . String

Optionally specify a category name and configure it in the log4j2.xml file to behave per your use case. For example, you can route log messages based on category or set log levels based on category.

category="MyCustomCategory"

XML Editor or Standalone

# A logger set to monitor message processing status
<logger category="monitoring" message="Message #[payload.id] processed successfully" level="INFO" doc:name="Monitoring Logger"/>

# A logger set to record the processing time of a flow
<logger category="performance" message="Message #[payload.id] took #[flowVars['processingTime']] milliseconds to process" level="INFO" doc:name="Performance Logger"/>
Element Description

logger

Use the Logger to log messages such as error messages, status notifications, or exceptions to the application’s log file.

Element Attribute Description

message

Specify what Mule should log. Supports expressions.

level

Select one of the following levels: ERROR, WARN, INFO, DEBUG, or TRACE. If no level attribute is set, the logger will log at the DEBUG level.

category

Optional. Specify categories to route log entries according to business needs. Configure the categories in your log4j.properties file.

doc:name

Customize to display a unique name for the logger in your application.

Note: Attribute not required in Mule Standalone configuration.

Rather than specifying a single Mule expression in your logger message, you can embed as many expressions as you required for your use case. This allows you to give some context to what is being logged, and enables you to log multiple things at once.

For example:

<logger message="Current payload is #[payload] and the message ID is #[message.id]" level="INFO" doc:name="Logger"/>
Keep in mind that the act of logging implies a toString() function, that in some cases may alter or consume the message.

Configuring Custom Logging Settings

By default, the logger is set to log messages asynchronously and at a level greater than or equal to INFO, and thus discards log messages at the DEBUG or TRACE level.

As from Mule runtime 3.6.0, log4j1 has been replaced by log4j2 as the backend tool for managing loggings. This implies some backwards compatibility issues as the necessary configuration files in this new framework are different. Log4j2 also allows for asynchronous logging, which wasn’t previously available, and Mule now implements this by default, as it implies a substantial improvement in performance.

If you need to use synchronized logging, change where to send the logs, adjust the logging level, or define custom categories, you can configure these properties in an XML file that specifies how the logger behaves, otherwise, use the default properties.

For instructions on how to edit these settings, see Logging in Mule.

See Also