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

  • Using a Log4j appender and external log forwarding at the same time might lead to duplicate log collection. Use one or the other.

  • 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 enabled by default. When you install Runtime Fabric, the parameter is enabled in Values.yaml. Even though the value is set to true, you must add an appender. To disable Log4j, set the value to false.

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