Send data via Mulesoft to your Logstash instance provided by Logit.io

Mulesoft

Ship Mule application logging entries to Logstash and Elasticsearch using Socket Appender

Use AnypointStudio and configure log4j using Socket Appender to ship Mule application logging entries to Logstash or Elasticsearch.

Step 1 - Locate your log4j2.xml file

In Anypoint Studio you can configure your log4j2.xml file under the location src/main/resources.

Step 2 - Configuring log4j2.xml

You will need to add the Socket appender to the log4j2.xml file. Under the RollingFile tag, inside the Appenders tag add the following snippet swapping the variables for the:

<Socket name="socket" host="your-logstash-host" port="your-port" protocol="ssl">
<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>

Then inside the tag AsyncRoot level="Info" you will need to add:

<AppenderRef ref="socket" />

After adding these two snippets to your file your log4j2.xml file it should look like the example below:

<?xml version="1.0" encoding="utf-8"?>
<Configuration>
    <Appenders>
        <RollingFile name="file" fileName="${sys:mule.home}${sys:file.separator}logs${sys:file.separator}test.log" 
                filePattern="${sys:mule.home}${sys:file.separator}logs${sys:file.separator}test-%i.log">
            <PatternLayout pattern="%d [%t] %-5p %c - %m%n" />
            <SizeBasedTriggeringPolicy size="10 MB" />
            <DefaultRolloverStrategy max="10"/>
        </RollingFile>
        
        <Socket name="socket" host="your-logstash-host" port="your-port" protocol="ssl">
        <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>
        
    </Appenders>
    <Loggers>
        <!-- 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"/>
        
        <AsyncRoot level="INFO">
            <AppenderRef ref="file" />
            <AppenderRef ref="socket" />
        </AsyncRoot>
    </Loggers>
</Configuration>
expand view

Expand View

compact view

Compact View

Return to Search
Sign Up