---
title: Configure Log4J Logging for Mule ESB with Nodinite – Step-by-Step Guide
description: Enable advanced logging from Mule ESB flows using Log4J with Nodinite. Learn how to configure custom appenders, filter logs, and unlock seamless integration monitoring.
---

# Configuring Log4J

Unlock powerful, business-driven logging for your Mule ESB integrations with <span class="nodinite-product-name" title="The node that unites different systems. Or as we call it Nodinite">Nodinite</span> and Log4J! This guide shows you how to configure Log4J for seamless log capture, filtering, and integration with Nodinite—empowering you to monitor, troubleshoot, and optimize your flows with confidence. <i class="fal fa-cogs" aria-hidden="true"></i> <i class="fal fa-search" aria-hidden="true"></i>

Mule messages and context are captured using the robust **Log4J** framework. This page describes the configuration steps required to enable advanced logging with Nodinite.

<aside aria-label="Tip" class="nodinite-note nodinite-note--tip">
<p class="nodinite-note__label" aria-hidden="true"><i class="far fa-fw fa-lightbulb"></i> Tip</p>
<div class="nodinite-note__content"><p>For even more flexibility and business value, consider using the <span class="nodinite-product-name" title="The node that unites different systems. Or as we call it Nodinite">Nodinite</span> Logging <a href="https://docs.nodinite.com/logging-and-monitoring/mulesoft-anypoint-platform-logging/features/custom-connector/">Custom Connector</a> instead of Log4J appenders.</p></div>
</aside>

The **Log4J configuration file**, `log4j2.xml`, is typically found in your Mule ESB project at:  
![Log4J_Studio][Log4J_Studio]  
*Default location of log4j2.xml in Mule ESB Studio.*  

You can also edit the Log4J configuration file after deployment. For example, it may be located here:  
![Log4J_Apps][Log4J_Apps]  
*Example of log4j2.xml location after deployment.*  

To filter and forward the right log files to <span class="nodinite-product-name" title="The node that unites different systems. Or as we call it Nodinite">Nodinite</span>, add a custom appender `<IMLogFileAppender>` under the `<Appenders>` section.  
The `<Configuration>` element must include the **packages** attribute set to **se.integrationsoftware.integrationmanager**.  
Ensure the directory in the `filePath` attribute exists and that the Log-Agent service account has read/write permissions.  

```xml
<?xml version="1.0" encoding="utf-8"?>
<Configuration packages="se.integrationsoftware.integrationmanager">
    <Appenders>
        <!--  IMLog File Appender -->
        <IMLogFileAppender name="file_IMLog" 
            filePath="${sys:mule.home}${sys:file.separator}logs${sys:file.separator}IMLog${sys:file.separator}filetransfer-">
    		    		
            <ScriptFilter onMatch="ACCEPT" onMisMatch="DENY">
                <Script name="GroovyFilter" language="groovy"><![CDATA[
		            if (logEvent.getMessage().getFormattedMessage().contains("im_") ) {
		                return true;
		            }
		            return false;
                ]]></Script>
            </ScriptFilter>
    		
            <PatternLayout pattern="%d [%t] %-5p %c - %m%n" />
        </IMLogFileAppender>
    </Appenders>    
    <Loggers>
        <!-- Mule classes -->
        <AsyncLogger name="org.mule" level="INFO"/>
        <AsyncLogger name="com.mulesoft" level="INFO"/>
        
        <AsyncRoot level="INFO">
            <AppenderRef ref="file_IMLog" />
        </AsyncRoot>
    </Loggers>
</Configuration>
```

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

![JavaPackage_Studio][JavaPackage_Studio]  
*Java package structure for IMLogFileAppender class.*  

```java
package se.integrationsoftware.integrationmanager;

import java.io.FileOutputStream;
import java.io.Serializable;
import java.util.UUID;
import java.util.concurrent.locks.*;
import org.apache.logging.log4j.core.*;
import org.apache.logging.log4j.core.appender.*;
import org.apache.logging.log4j.core.config.plugins.*;
import org.apache.logging.log4j.core.layout.PatternLayout;

@Plugin(name="IMLogFileAppender", category="Core", elementType="appender", printObject=true)
public final class IMLogFileAppender extends AbstractAppender {

    private static final long serialVersionUID = -2207607975964605180L;
	
    private final ReadWriteLock rwLock = new ReentrantReadWriteLock();
    private final Lock readLock = rwLock.readLock();

    private String filePath = "";

    private static long sequenceNumber = 0;
    
    protected IMLogFileAppender(String name, Filter filter, Layout<? extends Serializable> layout, final boolean ignoreExceptions) {
        super(name, filter, layout, ignoreExceptions);
    }

    protected IMLogFileAppender(String name, Filter filter, Layout<? extends Serializable> layout, final boolean ignoreExceptions, String filePath) {
        super(name, filter, layout, ignoreExceptions);
        
        this.filePath = filePath;
    }
    
    @Override
    public void append(LogEvent event) {
        readLock.lock();
        
        try {	
            final byte[] bytes = getLayout().toByteArray(event);
            
            UUID uuid = UUID.randomUUID();
            FileOutputStream fos = new FileOutputStream(filePath + String.format("%019d", sequenceNumber++) + "-" + uuid.toString() + ".log");
            fos.write(bytes);
            fos.close();           
        } catch (Exception ex) {
            if (!ignoreExceptions()) {
                throw new AppenderLoggingException(ex);
            }
        } finally {
            readLock.unlock();
        }
    }

    @PluginFactory
    public static IMLogFileAppender createAppender(
            @PluginAttribute("name") String name,
            @PluginElement("Layout") Layout<? extends Serializable> layout,
            @PluginElement("Filter") final Filter filter,
            @PluginAttribute("filePath") String filePath) {
    	
        if (name == null) {
            LOGGER.error("No name provided for IMLogFileAppender");
            return null;
        }
        
        if (layout == null) {	
            layout = PatternLayout.createDefaultLayout();
        }
        
        return new IMLogFileAppender(name, filter, layout, true, filePath);
    }
}
```

___

## <i class="fal fa-hand-point-right" aria-hidden="true"></i> Next Steps

* <i class="fal fa-square-plus" aria-hidden="true"></i> [Add or manage Log Agents][]  
* <i class="fal fa-rocket" aria-hidden="true"></i> [Install Mule Log Agent][Install]  
* <i class="fal fa-edit" aria-hidden="true"></i> [Configuration][] of the agent  

## <i class="fal fa-link-horizontal" aria-hidden="true"></i> Related Topics

* <i class="fal fa-search" aria-hidden="true"></i> [Log Views][]  
* <i class="fal fa-box-archive" aria-hidden="true"></i> [Log Agents][]  
* <i class="fal fa-bolt" aria-hidden="true"></i> [Business Events][]  
* <i class="fal fa-file" aria-hidden="true"></i> [Logger][]  

[Add or manage Log Agents]:https://docs.nodinite.com/administration/log-management/log-agents/features/add-or-manage-log-agent/
[Business Events]:https://docs.nodinite.com/logging-and-monitoring/mulesoft-anypoint-platform-logging/features/business-events/
[Configuration]:https://docs.nodinite.com/logging-and-monitoring/mulesoft-anypoint-platform-logging/getting-started/configuration/
[Custom Connector]:https://docs.nodinite.com/logging-and-monitoring/mulesoft-anypoint-platform-logging/features/custom-connector/
[Install]:https://docs.nodinite.com/logging-and-monitoring/mulesoft-anypoint-platform-logging/getting-started/install/
[JavaPackage_Studio]:https://docs.nodinite.com/media/Documentation%20Pictures/LogAgent/Mule/JavaPackage_Studio.png
[Log Agents]:https://docs.nodinite.com/administration/log-management/log-agents/features/what-is-a-log-agent/
[Log Views]:https://docs.nodinite.com/administration/log-management/log-views/features/what-is-a-log-view/
[Log4J_Apps]:https://docs.nodinite.com/media/Documentation%20Pictures/LogAgent/Mule/Log4J_Apps.png
[Log4J_Studio]:https://docs.nodinite.com/media/Documentation%20Pictures/LogAgent/Mule/Log4J_Studio.png
[Logger]:https://docs.nodinite.com/logging-and-monitoring/mulesoft-anypoint-platform-logging/features/logger/