---
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 :Nodinite: 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. :fa-cogs: :fa-search:

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

>[!TIP]
>For even more flexibility and business value, consider using the :Nodinite: Logging [Custom Connector][] instead of Log4J appenders.

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 :Nodinite:, 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);
    }
}
```

___

## :fa-hand-point-right: Next Steps

* :fa-square-plus: [Add or manage Log Agents][]  
* :fa-rocket: [Install Mule Log Agent][Install]  
* :fa-edit: [Configuration][] of the agent  

## :fa-link-horizontal: Related Topics

* :fa-search: [Log Views][]  
* :fa-box-archive: [Log Agents][]  
* :fa-bolt: [Business Events][]  
* :fa-file: [Logger][]  

[Add or manage Log Agents]:{ndr}/Administration/1.%20Log%20Management/3.%20Log%20Agents/Features/Add%20or%20manage%20Log%20Agent.md
[Business Events]:{ndr}/Logging%20and%20Monitoring/MuleSoft%20-%20AnyPoint%20Platform%20-%20Logging/Features/Business%20Events.md
[Configuration]:{ndr}/Logging%20and%20Monitoring/MuleSoft%20-%20AnyPoint%20Platform%20-%20Logging/Getting%20started/3.%20Configuration.md
[Custom Connector]:{ndr}/Logging%20and%20Monitoring/MuleSoft%20-%20AnyPoint%20Platform%20-%20Logging/Features/Custom%20Connector.md
[Install]:{ndr}/Logging%20and%20Monitoring/MuleSoft%20-%20AnyPoint%20Platform%20-%20Logging/Getting%20started/2.%20Install.md
[JavaPackage_Studio]:{ndm}/Documentation%20Pictures/LogAgent/Mule/JavaPackage_Studio.png
[Log Agents]:{ndr}/Administration/1.%20Log%20Management/3.%20Log%20Agents/Features/What%20is%20a%20Log%20Agent.md
[Log Views]:{ndr}/Administration/1.%20Log%20Management/1.%20Log%20Views/Features/What%20is%20a%20Log%20View.md
[Log4J_Apps]:{ndm}/Documentation%20Pictures/LogAgent/Mule/Log4J_Apps.png
[Log4J_Studio]:{ndm}/Documentation%20Pictures/LogAgent/Mule/Log4J_Studio.png
[Logger]:{ndr}/Logging%20and%20Monitoring/MuleSoft%20-%20AnyPoint%20Platform%20-%20Logging/Features/Logger.md