Loading

How to send Mule application logging entries to Elasticsearch or the ELK Stack using the Socket Appender

Publiseringsdato: Mar 2, 2024
Oppgave

GOAL

Elasticsearch, one of the products that make up the ELK Stack, is a popular open-source full-text search and analysis engine. This article explains how to send Mule application log entries to Elasticsearch using the Socket Appender.   
Trinn
  1. Add the Socket appender entry to log4j. For example:

    <Socket name="socket" host="${sys:elk.host}" port="${sys:elk.port}" protocol="TCP">
      <PatternLayout pattern="{&quot;log_timestamp&quot;:&quot;%d&quot; ,&quot;log_thread&quot;:&quot;[%t]&quot; , &quot;log_level&quot;:&quot;%-5p&quot; , %m}%n" /> 
    </Socket>
    Note: "elk.host" and "elk.port" are the Elasticsearch server host and port to send the logging entries to. In the above example, you will need to pass the values as system properties. 
  2. Add SSL information when needed.  If the remote server is secured by TLS, please provide SSL configuration. The following example shows a 2-way SSL configuration where both truststore and keystore are configured:

    <Socket name="socket" host="${sys:elk.host}" port="${sys:elk.port}" protocol="TCP">
      <PatternLayout pattern="{&quot;log_timestamp&quot;:&quot;%d&quot; ,&quot;log_thread&quot;:&quot;[%t]&quot; , &quot;log_level&quot;:&quot;%-5p&quot; , %m}%n" /> 
      <SSL> 
        <KeyStore location="${sys:path}/elk.jks" password="changeit"/> 
        <TrustStore location="${sys:path}/elk.jks" password="changeit"/> 
      </SSL>
    </Socket>
  3. Configure the Mule application to log to the Socket appended within the log4j2.xml. For example:

<AsyncRoot level="INFO">
  <AppenderRef ref="FILE" />
  <AppenderRef ref="socket" />
</AsyncRoot>

Note: above steps work for CloudHub applications. Please reference Integrate with Your Logging System Using Log4j to understand how the Custom Log Appender works.   


 
Flere ressurser

A sample log4j2.xml which uses 2-way SSL and can be used in Cloudhub. 

Disclaimer: This example is provided as a reference for your own usage and it's not part of the official Mule product. Its use is considered a custom implementation and is not supported.
Knowledge-artikkelnummer

001115078

 
Laster
Salesforce Help | Article