---
schema_version: "1"
id: 570870585885d2750fcbe3427285b52cd6cdc9fa851615f685990091643c0fe9
title: Integrating with Your Logging System Using Log4j
collection: mulesoft
version: current
locale: en-us
portal_url: https://docs.salesforce.com/mulesoft/current/en-us/cloudhub-2/ch2-integrate-log-system.md
canonical_url: https://docs.mulesoft.com/cloudhub-2/ch2-integrate-log-system
source_site: docs.mulesoft.com
content_type: documentation
content_hash: 57a05b35a9b131f39dc8220767ef09fe4f7d7afd668a6b82ebdeed38dddc6192
description: MuleSoft Documentation Site
latest: true
---
---
product: CloudHub 2.0
---

# Integrating with Your Logging System Using Log4j

> For the full documentation index, see: https://docs.mulesoft.com/llms.txt

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.

> [!NOTE] 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](https://logging.apache.org/log4j/2.x/manual/configuration.html#ConfigurationSyntax).

## Example: Create a Log4j Configuration Using Splunk

> [!IMPORTANT] 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
    <?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>
    ```

    > [!NOTE] 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:

    ```xml
    <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](https://github.com/splunk/splunk-library-javalogging/tags).

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

## See Also

- [Deploying Apps to Private Spaces](https://docs.mulesoft.com/cloudhub-2/ch2-deploy-private-space)

- [Deploying Apps to Shared Spaces](https://docs.mulesoft.com/cloudhub-2/ch2-deploy-shared-space)
