How to send Mule application logging entries to SumoLogic

Apisero
5 min readApr 1, 2021

Author: Shruti Puri

In this blog we will try to learn how we can send logs to SumoLogic from MuleSoft using Sumologic Appender.

What is SumoLogic?

SumoLogic is a cloud-based machine data analytics company focusing on security, operations, and BI use cases. It provides log management and analytics services that leverage machine-generated big data to deliver real-time IT insights.

Register with SumoLogic:

  • Enter a specific region and sign-up.
  • Select Start streaming data to SumoLogic. Click on Get Started.
  • Select DataType-Your custom app.
  • Set Up collection-HTTPS Source.
  • Configure Source.
  • Copy URL to use later in SumoLogicAppender. Click Next to finish configuring the wizard.

Enable Custom Logging For On MuleSoft Runtime:

  • Go to Project.
  • Open src/main/resoruces/log4j2.xml.
  • Add SumoLogic logging appender to the classpath.

Please add the following dependency in pom.xml:

<dependency>
<groupId>com.sumologic.plugins.log4j</groupId>
<artifactId>sumologic-log4j2-appender</artifactId>
<version>1.1</version>
</dependency>

Configure log4j to load the SumoLogic package

<Configuration status=”info” name=”sumologic” packages=”com.sumologic.log4j”>

Tips: you can set status to “trace” to get log4j debug information

Add SumoLogic appender to log4j

<SumoLogicAppender name=”SumoAppender” url=”${sys:sumo.server}”>
<PatternLayout pattern=”%d{yyyy-MM-dd HH:mm:ss,SSS Z} [%t] %-5p %c — %m%n” />
</SumoLogicAppender>

Note: “sumo.server” is the URL provided by Sumologic to send the logging entries to. In the above example, you will need to pass the URL value to a system property with name “sumo.server”.

Configure Mule application to use the SumoLogic appender

<AsyncRoot level=”INFO”>
<AppenderRef ref=”FILE” />
<AppenderRef ref=”SumoAppender” />
</AsyncRoot>

  • Run Application.
  • See the Console Log.

Enable Custom Logging For CloudHub Application:

Before enabling the logging for cloudhub application, you need to Disable CloudHub logs. By default, this option is not available and you need to raise a ticket with MuleSoft for providing this option.

Once you disable cloudhub logs, MuleSoft is not responsible for the things below:

  • MuleSoft is not responsible for lost logging data due to misconfiguration of your own log4j appender.
  • MuleSoft is also not responsible for misconfigurations that result in performance degradation, running out of disk space, or other side effects.
  • When you disable the default CloudHub application logs, then only the system logs are available. For application worker logs, please check your own application’s logging system. Downloading logs is not an option in this scenario.
  • Only Asynchronous log appenders can be used, and Synchronous appenders should not be used.
  • Use asynchronous loggers and not synchronous ones is to avoid threading issues. Synchronous loggers can lock threads waiting for responses.

Below is full log4j2.xml which can be used for your application for enabling custom logging on cloudhub and http appender for SumoLogic.

<?xml version=”1.0″ encoding=”utf-8″?>
<Configuration status=”info” name=”cloudhub” packages=”com.mulesoft.ch.logging.appender,com.sumologic.log4j”>

<!–These are some of the loggers you can enable.
There are several more you can find in the documentation.
Besides this log4j configuration, you can also use Java VM environment variables
to enable other logs like network (-Djavax.net.debug=ssl or all) and
Garbage Collector (-XX:+PrintGC). These will be append to the console, so you will
see them in the mule_ee.log file. –>

<Appenders>
<RollingFile name=”file” fileName=”${sys:mule.home}${sys:file.separator}logs${sys:file.separator}APP_NAME.log”
filePattern=”${sys:mule.home}${sys:file.separator}logs${sys:file.separator}poc-sap-systemapi-%i.log”>
<PatternLayout pattern=”%d [%t] %-5p %c — %m%n” />
<SizeBasedTriggeringPolicy size=”10 MB” />
<DefaultRolloverStrategy max=”10″/>
</RollingFile>
<SumoLogicAppender
name=”SumoAppender”
url=”${sys:sumo.server}”>
<PatternLayout pattern=”%d{yyyy-MM-dd HH:mm:ss,SSS Z} [%t] %-5p %c — %m%n” />
</SumoLogicAppender>
<Log4J2CloudhubLogAppender name=”CLOUDHUB”
addressProvider=”com.mulesoft.ch.logging.DefaultAggregatorAddressProvider”
applicationContext=”com.mulesoft.ch.logging.DefaultApplicationContext”
appendRetryIntervalMs=”${sys:logging.appendRetryInterval}”
appendMaxAttempts=”${sys:logging.appendMaxAttempts}”
batchSendIntervalMs=”${sys:logging.batchSendInterval}”
batchMaxRecords=”${sys:logging.batchMaxRecords}”
memBufferMaxSize=”${sys:logging.memBufferMaxSize}”
journalMaxWriteBatchSize=”${sys:logging.journalMaxBatchSize}”
journalMaxFileSize=”${sys:logging.journalMaxFileSize}”
clientMaxPacketSize=”${sys:logging.clientMaxPacketSize}”
clientConnectTimeoutMs=”${sys:logging.clientConnectTimeout}”
clientSocketTimeoutMs=”${sys:logging.clientSocketTimeout}”
serverAddressPollIntervalMs=”${sys:logging.serverAddressPollInterval}”
serverHeartbeatSendIntervalMs=”${sys:logging.serverHeartbeatSendIntervalMs}”
statisticsPrintIntervalMs=”${sys:logging.statisticsPrintIntervalMs}”>

<PatternLayout pattern=”[%d{MM-dd HH:mm:ss}] %-5p %c{1} [%t] CUSTOM: %m%n” />
</Log4J2CloudhubLogAppender>
</Appenders>
<Loggers>

<AsyncRoot level=”INFO”>
<AppenderRef ref=”FILE” />
<AppenderRef ref=”SumoAppender” />

<AppenderRef ref=”CLOUDHUB” />
</AsyncRoot>

<!– Http Logger shows wire traffic on DEBUG –>
<AsyncLogger name=”org.mule.module.http.internal.HttpMessageLogger” level=”WARN”/>

<!– JDBC Logger shows queries and parameters values on DEBUG –>
<AsyncLogger name=”com.mulesoft.mule.transport.jdbc” level=”WARN”/>

<!– CXF is used heavily by Mule for web services –>
<AsyncLogger name=”org.apache.cxf” level=”WARN”/>

<!– Apache Commons tend to make a lot of noise which can clutter the log–>
<AsyncLogger name=”org.apache” level=”WARN”/>

<!– Reduce startup noise –>
<AsyncLogger name=”org.springframework.beans.factory” level=”WARN”/>

<!– Mule classes –>
<AsyncLogger name=”org.mule” level=”INFO”/>
<AsyncLogger name=”com.mulesoft” level=”INFO”/>

<!– Reduce DM verbosity –>
<AsyncLogger name=”org.jetel” level=”WARN”/>
<AsyncLogger name=”Tracking” level=”WARN”/>

</Loggers>
</Configuration>

This is how you can enable SumoLogic logging for MuleSoft applications.

--

--