Logging in MUnit

MUnit allows you to have a log configuration specifically for your tests. In this way, you can log information differently from the way that your Mule application logs. To do this, you need a file called log4j2-test.xml with the desired log configuration for your tests. This file overrides any log configuration for Mule applications, but it is used only when running MUnit tests.

An example of a log4j2-test.xml file is shown below.

<?xml version="1.0" encoding="UTF-8"?>
        <Console name="Console" target="SYSTEM_OUT">
            <PatternLayout pattern="%-5p %d [%t] %c: %m%n"/>
        <!-- CXF is used heavily by Mule for web services -->
        <AsyncLogger name="org.apache.cxf" level="WARN"/>
        <!-- Apache Commons tend to make a lot of noise which can clutter the log-->
        <AsyncLogger name="org.apache" level="WARN"/>
        <!-- Reduce startup noise -->
        <AsyncLogger name="org.springframework.beans.factory" level="WARN"/>
        <!-- Mule classes -->
        <AsyncLogger name="org.mule" level="INFO"/>
        <AsyncLogger name="com.mulesoft" level="INFO"/>
        <AsyncLogger name="org.mule.api.processor.LoggerMessageProcessor" level="DEBUG"/>

        <AsyncRoot level="INFO">
            <AppenderRef ref="Console"/>

This configuration disables logs like cxf or apache commons. It also sets the logger message processor to DEBUG mode. If you don’t specify the logging mode the default is ERROR.

The configuration file must reside in the classpath to work correctly. Preferably, the file should reside in the src/test/resources folder, since this a resource you use when running your tests, and the folder belongs to the classpath.
If you don’t create a log4j2-test.xml file, Mule looks for a file called log4j2.xml. For additional information about the priority in which the log configuration files are selected, see Logging in Mule.

See Also

Was this article helpful?

💙 Thanks for your feedback!

Edit on GitHub
Give us your feedback!
We want to build the best documentation experience for you!
Help us improve with your feedback.
Take the survey!