Integrating Logstash with JBoss

Logstash is one of the hottest tools when it comes to log management. There are lots of integration possibilities in standalone or web applications. But what if you want to capture the whole log output of your JBoss server? Take a look at the snippets.

JBoss 4

Take the following 3 steps in order to integrate logstash using JBoss 4:

  1. Download logstash-gelf-1.4.0-logging-module.zip
  2. Extract logstash-gelf-1.4.0.jar and json-simple-1.1.jar into your server’s lib directory (server/<instance>/lib)
    Optional: Copy also jedis-2.4.2.jar if you plan to use Redis instead of GELF
  3. Add following code to your jboss-log4j.xml (server/<instance>/conf):
<appender name="GelfLogger" class="biz.paluch.logging.gelf.log4j.GelfLogAppender">
  <param name="Threshold" value="INFO"/>
  <param name="Host" value="<Your Logstash Host>"/>
  <param name="Facility" value="JBoss 4"/>
  <param name="ExtractStackTrace" value="true"/>
  <param name="FilterStackTrace" value="true"/>
  <param name="MdcProfiling" value="true"/>
  <param name="AdditionalFields" value="Environment=Test"/>
  <param name="MdcFields" value="remoteAddr,remoteUser,sessionId,requestUri,requestMethod"/>
</appender>

<root>
  <appender-ref ref="CONSOLE";/>
  <appender-ref ref="FILE"/>
  <appender-ref ref="GelfLogger"/>
</root>

You can find a complete XML file on Github.

JBoss 7/Wildfly

Take the following 3 steps in order to integrate logstash using JBoss AS7/Wildfly:

  1. Download logstash-gelf-1.4.0-logging-module.zip
  2. Extract the file into your JBoss 7/8 modules directory, so you get the following directory structure <Server>/modules/biz/paluch/logging/main (or if you use layers, <Server>/modules/system/layers/base/biz/paluch/logging/main)
  3. Add following code to your config (server/<instance>/conf):
<custom-handler name="GelfLogger" class="biz.paluch.logging.gelf.jboss7.JBoss7GelfLogHandler"
                module="biz.paluch.logging">
    <level name="INFO" />
    <properties>
        <property name="host" value="<Your Logstash Host>" />
        <property name="extractStackTrace" value="true" />
        <property name="filterStackTrace" value="true" />
        <property name="mdcProfiling" value="true" />
        <property name="facility" value="JBoss AS7/AS8" />
        <property name="additionalFields" value="Environment=Test" />
        <property name="mdcFields" value="remoteAddr,remoteUser,sessionId,requestUri,requestMethod" />
    </properties>
</custom-handler>

<root-logger>
    <level name="INFO"/>
    <handlers>
        <handler name="CONSOLE"/>
        <handler name="FILE"/>
        <handler name="GelfLogger"/>
    </handlers>
</root-logger>

If you like to add the config using CLI, take a look at add-gelf-logger.cli

You can find the full documentation of logstash-gelf at http://logging.paluch.biz/

The Github Repo is located at https://github.com/mp911de/logstash-gelf

You may also enjoy…