Question

How would I configure the JBoss log system to use a custom log4j layout like log4j-json or a custom JUL formatter like logstash-util-formatter?

Edit: it looks like custom formatters are available in WildFly 8 and they are coming in EAP 6.3.

In the meantime, I think I have these options which involve bypassing JBoss logging:

  1. Use per-deployment logging to configure log4j myself.
  2. Use jboss-deployment-structure.xml to block EAP's log libraries and use something like logback with a JSON encoder like this.

Either way, I would only get JSON logging for the deployment itself, not for datasources and container startup. Is there another option which would allow all logging to be in JSON format?

Était-ce utile?

La solution

It's not possible in JBoss AS 7.x or JBoss EAP 6.2. As you said though it is available in WildFly 8.0.0.Final as a custom-formatter and will be available in JBoss EAP 6.3.

Actually it is possible, but you'd lose the ability to do runtime changes to the logging configuration. You could remove the logging subsystem and purely use the logging.properties configuration. I'd probably not suggest that unless you desperately need to use the formatter and can't wait for EAP 6.3 or use WildFly.

Autres conseils

An alternative approach is using logstash-gelf (https://github.com/mp911de/logstash-gelf) which brings a native log handler for GELF.

This way you do not need to wait for a JSON formatter, just configure a GELF input on your logstash and grab the logger module (http://search.maven.org/remotecontent?filepath=biz/paluch/logging/logstash-gelf/1.5.4/logstash-gelf-1.5.4-logging-module.zip). Works with JBoss AS7 (EAP6) and WildFly.

JBoss config snippet

<custom-handler name="GelfLogger" class="biz.paluch.logging.gelf.jboss7.JBoss7GelfLogHandler" module="biz.paluch.logging">
    <level name="INFO" />
    <properties>
        <property name="host" value="udp:localhost" />
        <property name="port" value="12201" />      
        <property name="includeFullMdc" value="true" />
    </properties>
</custom-handler>

Configure JBoss EAP with JSON log formatter for Red Hat JBoss Enterprise Application Platform (EAP) 6.4 7.x:

<subsystem xmlns="urn:jboss:domain:logging:3.0">
    <formatter name="JSONFMT">
        <custom-formatter class="org.jboss.logmanager.formatters.JsonFormatter" module="org.jboss.logmanager.json-formatter"/>
    </formatter>

    <periodic-rotating-file-handler name="JSON" autoflush="true">
        <formatter>
            <named-formatter name="JSONFMT"/>
        </formatter>
        <file relative-to="jboss.server.log.dir" path="xserver.log"/>
        <suffix value=".yyyy-MM-dd"/>
        <append value="true"/>
    </periodic-rotating-file-handler>
    <root-logger>
        <level name="INFO"/>
        <handlers>
            <handler name="CONSOLE"/>
            <handler name="FILE"/>
            <handler name="JSON"/>
        </handlers>
    </root-logger>
    <formatter name="JSONFMT">
        <custom-formatter class="org.jboss.logmanager.formatters.JsonFormatter" module="org.jboss.logmanager.json-formatter"/>
    </formatter>
</subsystem>

JsonFormatter implements org.jboss.logmanager.ExtFormatter and installed as module into modules dir.

Check https://github.com/jboss-logging/jboss-logmanager/tree/main/ext/src/main/java/org/jboss/logmanager/ext/formatters for inspiration.

Alternative solution is to exclude JBoss logmanager from classpath and use whatever modern tool you want, see my answer: Logback and Jboss 7 - don't work together?

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top