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 anytime: 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.

By default Mule Studio will not log messages at the DEBUG or TRACE level to the console unless you create a configure a [log4j.properties file] in src/main/resources to lower the log level

level="INFO"

Category

Optional String.

Optionally specify a category name and configure it in the [log4j.properties 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 log multiple things at once.

For example:

<logger message="Current payload is #[payload] and 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 the log4j.properties File

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

If you need to adjust the logging level or define customer categories, you can configure your log4j.properties file to define how the logger behaves. In Mule Standalone, your log4j.properties files in your $MULE_HOME.conf folder. In Anypoint Studio, you need to create the log4j.properties file under src/main/resources. A sample file is provided below.

Example log4j.properties file
# Default log level
log4j.rootCategory=INFO, console
log4j.appender.console=org.apache.log4j.ConsoleAppender
log4j.appender.console.layout=org.apache.log4j.PatternLayout
log4j.appender.console.layout.ConversionPattern=%-5p %d [%t] %c: %m%n
################################################
# You can set custom log levels per-package here
################################################
# CXF is used heavily by Mule for web services
log4j.logger.org.apache.cxf=WARN
# Apache Commons tend to make a lot of noise which can clutter the log.
log4j.logger.org.apache=WARN
# Reduce startup noise
log4j.logger.org.springframework.beans.factory=WARN
# Mule classes
log4j.logger.org.mule=INFO
log4j.logger.com.mulesoft=INFO
# Reduce DM verbosity
log4j.logger.org.jetel=WARN
log4j.logger.Tracking=WARN

See Also