Fork me on GitHub

WildFly JSON Formatter

Following settings can be used:

Attribute Name Description Default
lineBreak End of line string \n
fields Comma-separated list of log event fields that should be included in the JSON Time, Severity, ThreadName, SourceClassName, SourceMethodName, SourceSimpleClassName, LoggerName, NDC, Server
version GELF Version 1.0 or 1.1 1.0
originHost Originating Hostname FQDN Hostname
extractStackTrace Send the Stack-Trace to the StackTrace field (true/false) false
filterStackTrace Perform Stack-Trace filtering (true/false) false
includeLogMessageParameters Include message parameters from the log event true
includeLocation Include source code location true
facility Name of the Facility logstash-gelf
mdcProfiling Perform Profiling (Call-Duration) based on MDC Data. See MDC Profiling for details false
additionalFields Send additional static fields. The fields are specified as key-value pairs are comma-separated. Example: additionalFields=fieldName=Value,fieldName2=Value2 none
additionalFieldTypes Type specification for additional and MDC fields. Supported types: String, long, Long, double, Double and discover (default if not specified, discover field type on parseability). Eg. field=String,field2=double discover for all additional fields
mdcFields Send additional fields whose values are obtained from MDC. Name of the Fields are comma-separated. Example: mdcFields=Application,Version,SomeOtherFieldName none
dynamicMdcFields Dynamic MDC Fields allows you to extract MDC values based on one or more regular expressions. Multiple regexes are comma-separated. The name of the MDC entry is used as GELF field name. none
dynamicMdcFieldTypes Pattern-based type specification for additional and MDC fields. Key-value pairs are comma-separated. Example: my_field.*=String,business\..*\.field=double none
includeFullMdc Include all fields from the MDC. false
timestampPattern Date/time pattern for the Time field yyyy-MM-dd HH:mm:ss,SSS

The JSON formatter creates then messages like:

    "LoggerName": "org.wildfly.extension.undertow",
    "short_message": "WFLYUT0008: Undertow HTTP listener default suspending",
    "level": "6",
    "Time": "2015-08-11 21:25:32,0734",
    "Severity": "INFO",
    "MessageParam1": "default",
    "Thread": "MSC service thread 1-6",
    "SourceMethodName": "stopListening",
    "MessageParam0": "HTTP",
    "full_message": "WFLYUT0008: Undertow HTTP listener default suspending",
    "SourceSimpleClassName": "HttpListenerService",
    "SourceClassName": "org.wildfly.extension.undertow.HttpListenerService",
    "facility": "logstash-gelf",
    "timestamp": "1439321132.734"

Default line break is \n, JSON objects are separated by line breaks only.

Preliminary Steps

If you want to get started with the logstash-gelf support for WildFly, you will need to integrate logstash-gelf as a module within the server. It is possible to create the module manually, but it's easier to use the prepackaged binary. Please follow the steps to integrate the module:

  1. Obtain the logging module from Maven or Github
  2. Extract the module to <WildFly Home>/modules/system/layers/base.
  3. Configure the logging subsystem by either adopting the changes in the XML files or by using the CLI

WildFly Logging configuration

XML Configuration:

<formatter name="JsonFormatter">
    <custom-formatter module="biz.paluch.logging" class="biz.paluch.logging.gelf.wildfly.WildFlyJsonFormatter">
            <property name="version" value="1.0" />
            <property name="facility" value="logstash-gelf" />
            <property name="fields" value="Time,Severity,ThreadName,SourceClassName,SourceMethodName,SourceSimpleClassName,LoggerName,NDC" />
            <property name="extractStackTrace" value="true" />
            <property name="filterStackTrace" value="true" />
            <property name="includeLogMessageParameters" value="true" />
            <property name="includeLocation" value="true" />
            <property name="mdcProfiling" value="true" />
            <property name="timestampPattern" value="yyyy-MM-dd HH:mm:ss,SSS" />
            <property name="additionalFields" value="fieldName1=fieldValue1,fieldName2=fieldValue2" />
            <property name="additionalFieldTypes" value="fieldName1=String,fieldName2=Double,fieldName3=Long" />
            <property name="mdcFields" value="mdcField1,mdcField2" />
            <property name="dynamicMdcFields" value="mdc.*,(mdc|MDC)fields" />
            <property name="includeFullMdc" value="true" />

<file-handler name="JsonLog">
    <file relative-to="jboss.server.log.dir" path="server.json"/>

    <level name="INFO"/>
        <handler name="FILE"/>
        <handler name="CONSOLE"/>
        <handler name="JsonLog"/>

CLI Configuration:

/subsystem=logging/custom-formatter=JsonFormatter/:add(module=biz.paluch.logging,class=biz.paluch.logging.gelf.wildfly.WildFlyJsonFormatter,properties={ \
       version="1.0", \
       facility="logstash-gelf", \
       fields="Time,Severity,ThreadName,SourceClassName,SourceMethodName,SourceSimpleClassName,LoggerName,NDC", \
       extractStackTrace=true, \
       filterStackTrace=true, \
       includeLogMessageParameters=true, \
       includeLocation=true, \
       mdcProfiling=true, \
       timestampPattern="yyyy-MM-dd HH:mm:ss,SSS", \
       additionalFields="fieldName1=fieldValue1,fieldName2=fieldValue2", \
       additionalFieldTypes="fieldName1=String,fieldName2=Double,fieldName3=Long", \
       mdcFields="mdcField1,mdcField2" \
       dynamicMdcFields="mdc.*,(mdc|MDC)fields" \
       dynamicMdcFieldTypes="my_field.*=String,business\..*\.field=double" \
       includeFullMdc=true \

/subsystem=logging/file-handler=JsonLog/:add(file={"relative-to"=>"jboss.server.log.dir", path=server.json}, \