0

How can I enable wildfly swarm logging to greylog - or put in other words: do logging in gelf format? Has anyone done this already?

It seems there are only framworkes on the graylog marketplace that work together with log4j (gelfj) or logback but not with the jboss logging system. And from other questions on SO I assume that it's not possible to configure thorntail to log with log4j (which would feel somewhat wrong anyway: pipe logging through jboss logging in to log4j to funnel it into gelf ..)

The underlying requirement is that I want to docker my swarm application and use greylog as centralized logging. I understand that I can configure docker to log into gelf but that would mean I do not have control over the extended gelf functions in my application, right?

What would be the preferred way to achieve centralized logging from thorntail/swarm?

Lasrik
  • 589
  • 1
  • 8
  • 22

1 Answers1

0

Yes it is possible to send logs to graylog in thorntail, because some has implemented a jboss compatible gelf log handler for us. Some restrictions would be which logging framework you use. I had to use the jboss logger via slf4j and did not spend more time to get log4j running. Maybe you find out how this can be achieved.

Where do I get a jboss compatible log handler for gelf?

Here you find the git repository of the jboss compatible log handler which supports gelf format.

https://github.com/mp911de/logstash-gelf

How do I configure the log handler?

See the following link for the doc of this log handler.

https://logging.paluch.biz/

How do I integrate it in thorntail?

For that you have to do some work.

1. Add the dependcy to your pom.xml

  <dependency>
        <groupId>biz.paluch.logging</groupId>
        <artifactId>logstash-gelf</artifactId>
        <version>1.12.0</version>
        <scope>provided</scope>
    </dependency>

2. Create a custom module.xml for thorntail

src/main/resources/modules/biz/paluch/logging/main/module.xml

<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.3" name="biz.paluch.logging">
    <resources>
        <artifact name="biz.paluch.logging:logstash-gelf:1.11.2" />
        <artifact name="redis.clients:jedis:2.9.0" />
        <artifact name="org.apache.commons:commons-pool2:2.4.3" />
    </resources>

    <dependencies>
        <module name="org.apache.log4j" />
        <module name="org.slf4j" />
        <module name="javax.api" />
        <module name="org.jboss.logmanager" />
    </dependencies>
</module>

3. Configure thorntail to use this log handler

swarm:
  jaeger:
  logging:
    file-handlers:
    custom-handlers:
      GELF-HTTP:
        named-formatter: MY_LOG_PATTERN
        attribute-class: biz.paluch.logging.gelf.wildfly.WildFlyGelfLogHandler
        module: biz.paluch.logging
        properties:
          host: "http://graylog"
          extractStackTrace: true
          includeFullMdc: true
          maximumMessageSize: 1048576
    root-logger:
      level: WARN
      handlers:
        - CONSOLE
        - GELF-HTTP

How to make the logger available in my application?

import org.jboss.logging.Logger;
import org.slf4j.LoggerFactory;

import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.context.Dependent;
import javax.enterprise.inject.Default;
import javax.enterprise.inject.Produces;
import javax.enterprise.inject.spi.InjectionPoint;

/**
 * This produces and configures the logger.
 *
 * @author Thomas Herzog <herzog.thomas81@gmail.com>
 * @since 06/08/18
 */
@ApplicationScoped
public class LoggerConfiguration {

    @Produces
    @Default
    @Dependent
    Logger createLogger(final InjectionPoint ip) {
        if (ip.getBean() != null) {
            return Logger.getLogger(ip.getBean().getBeanClass());
        } else if (ip.getMember() != null) {
            return Logger.getLogger(ip.getMember().getDeclaringClass());
        } else {
            return Logger.getLogger("default");
        }
    }
}
Thomas Herzog
  • 506
  • 2
  • 6