Contact Us 1-800-596-4880

Integrating with Your Logging System Using Log4j

You can stream Mule runtime logs, application logs, and tracing-module logs from CloudHub 2.0 to an external collector by configuring a custom asynchronous Log4j appender. This enables you to send logs to destinations such as Splunk, Azure Monitor, or any other external logging system that accepts Log4j output.

External collectors such as Azure Monitor or a Telemetry Exporter are valid destinations for CloudHub 2.0 logs. These are reached as generic external collectors via a custom Log4j appender, they don’t have a dedicated built-in connector in CloudHub 2.0.

Requirements and Restrictions

  • Log appenders must be asynchronous. Synchronous appenders aren’t supported.

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

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

  • MuleSoft isn’t 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

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

  • You can forward tracing module logs using only third-party appenders. You can’t update the logging patterns to send them to Anypoint Monitoring.

  • Console logging is disabled by default in CloudHub 2.0. If you change log levels or appenders in a custom log4j2.xml and don’t see the changes in the logs, use an appender that CloudHub 2.0 collects, such as a third-party appender that streams to your logging system. Log output from a Console appender alone doesn’t appear in Runtime Manager.

You can use any asynchronous Log4j appender.

For information about configuring log4j2.xml, see the Log4j Configuration Syntax.

Example: Create a Log4j Configuration Using Splunk

Console logging is disabled by default in CloudHub 2.0. If you rely only on a Console appender, changes to log levels or appenders in your custom log4j2.xml might not appear in the logs in Runtime Manager. To apply your custom Log4j configuration, use an appender that streams logs to an external system, such as Splunk, or enable log integration for your deployment to collect console output.

For logs to be viewable in CloudHub 2.0 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.splunk.logging,org.apache.logging.log4j">
        <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>
    Deploying an app to CloudHub 2.0 configures AnypointMonitoringFileAppender automatically, so you don’t need to configure it in log4j2.xml.
  2. 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.