Contact Us 1-800-596-4880

Integrating with Your Logging System Using Log4j

You can use a Log4j appender to integrate your logging system with applications deployed to Runtime Fabric.

You can use any Log4j appender. For information about configuring log4j2.xml, see the Log4j Configuration Syntax.

Requirements and Restrictions

  • MuleSoft Support doesn’t assist in implementing custom logging configurations or resolving issues caused by custom logging configurations.

  • MuleSoft is not responsible for issues arising from misconfiguration of your Log4j appender, including these or other issues:

    • Lost logging data

    • Performance degradation

    • Running out of disk space

  • Do not use synchronous log appenders.

    You can use only asynchronous log appenders.

  • File appenders, such as FileAppender, RollingFileAppender, AnypointMonitoringFileAppender, and RandomAccessFileAppender, are removed automatically.

  • When using custom Log4j configurations, both Mule runtime engine and application logs remain available in Anypoint Monitoring.

Enabling Log4j

Custom Log4j configurations are disabled by default. When you install Runtime Fabric, the parameter is disabled (false) in Values.yaml. You must set the value to true.

You can also enable custom Log4j configurations by running the following steps:

  1. From inside your cluster, run:

    kubectl -nrtf patch secret custom-properties -p '{"data":{"CUSTOM_LOG4J_ENABLED":"dHJ1ZQ=="}}'
  2. Restart the Runtime Fabric agent pod.

  3. Restart the application associated with the custom Log4j configuration.

Configure Custom Log4j and Anypoint Monitoring Logs

To use custom Log4j and Anypoint Monitoring logging at the same time, you must add a specific Anypoint Monitoring console appender pattern to your app log4j2.xml file:

  1. In the log4j2.xml file, define your console appender pattern, for example:

    <Console name="Console" target="SYSTEM_OUT">
        <PatternLayout pattern="${env:MULE_LOG_PATTERN:-%m%n}"/>
    </Console>
  2. In the <AsyncRoot> element define the AppenderRef element, which references the console pattern you previously created:

    <AsyncRoot level="INFO">
        <AppenderRef ref="Console"/>
    </AsyncRoot>
Custom Log4j is only supported by Mule applications running on Mule runtime engine instances greater than or equal to Mule version 4.3.0. The Mule image must be built after Nov 17, 2022. For details, refer to the Runtime Fabric Release Notes.

Example: Create a Log4j Configuration Using Splunk

For logs to be viewable in Runtime Fabric and flow to Splunk, configure the SplunkHttp Log4j appender.

To enable the Log4j appender:

  1. Update the log4j2.xml configuration file with your logger settings and include the SplunkHttp Log4j appender.

    In Anypoint Studio, the log4j2.xml file is located in the src/main/resources directory.

<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="INFO" name="cloudhub" packages="com.mulesoft.ch.logging.appender">
    <Appenders>
    	<Console name="CONSOLE" target="SYSTEM_OUT">
            <PatternLayout pattern="[%d{MM-dd HH:mm:ss}] %-5p %c{1} [%t]: %m%n"/>
        </Console>
        <SplunkHttp name="SPLUNK"
        	source="${env:APP_NAME}"
        	host="${env:POD_NAME}"
        	sourceType="mule-app"
            url="${sys:splunk.host}"
            token="${sys:splunk.token}"
            index="main">
            <PatternLayout pattern="[%d{MM-dd HH:mm:ss}] %-5p %c{1} [%t]: %m%n" />
        </SplunkHttp>
    </Appenders>
    <Loggers>
        <AsyncRoot level="INFO">
            <AppenderRef ref="CONSOLE"/>
            <AppenderRef ref="SPLUNK"/>
        </AsyncRoot>
    </Loggers>
</Configuration>
  1. Ensure that the configuration includes the Splunk dependency:

    <dependency>
       <groupId>com.splunk.logging</groupId>
       <artifactId>splunk-library-javalogging</artifactId>
       <version>x.x.x</version>
    </dependency>
    *********
    ******************
    <repository>
       <id>splunk-artifactory</id>
       <name>Splunk Releases</name>
       <url>https://splunk.jfrog.io/splunk/ext-releases-local</url>;
    </repository>

    For the latest version of Splunk, see GitHub.

After your application starts, logs start flowing to your custom Log4j appender, and you can view them on your target logging system.

See Also