I can't connect to graylog from maven java application with Wilfly

Hi, this is my first time I am using graylog. So please don’t kill if my question is too basic.
I have to connect an existing java 8 application with maven and running in Wilfly with graylog.

The first thing I tried was run a test graylog project.
This project run a docker graylog.

This is the docker-compose.yaml file:

version: '2'
services:
    # MongoDB: https://hub.docker.com/_/mongo/
    mongodb:
        image: mongo:3
        volumes:
            - mongo_data:/data/db
    # Elasticsearch: https://www.elastic.co/guide/en/elasticsearch/reference/6.x/docker.html
    elasticsearch:
        image: docker.elastic.co/elasticsearch/elasticsearch-oss:6.8.2
        volumes:
            - es_data:/usr/share/elasticsearch/data
        environment:
            - http.host=0.0.0.0
            - transport.host=localhost
            - network.host=0.0.0.0
            - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
        ulimits:
            memlock:
                soft: -1
                hard: -1
        mem_limit: 1g
    # Graylog: https://hub.docker.com/r/graylog/graylog/
    graylog:
        image: graylog/graylog:3.1
        volumes:
            - graylog_journal:/usr/share/graylog/data/journal
        environment:
            # CHANGE ME (must be at least 16 characters)!
            - GRAYLOG_PASSWORD_SECRET=somepasswordpepper
            # Password: admin
            - GRAYLOG_ROOT_PASSWORD_SHA2=8c6976e5b5410415bde908bd4dee15dfb167a9c873fc4bb8a81f6f2ab448a918
            - GRAYLOG_HTTP_EXTERNAL_URI=http://127.0.0.1:9000/
        links:
            - mongodb:mongo
            - elasticsearch
        depends_on:
            - mongodb
            - elasticsearch
        ports:
            # Graylog web interface and REST API
            - 9000:9000
            # Syslog TCP
            - 1514:1514
            # Syslog UDP
            - 1514:1514/udp
            # GELF TCP
            - 12201:12201
            # GELF UDP
            - 12201:12201/udp
# Volumes for persisting data, see 
volumes:
    mongo_data:
        driver: local
    es_data:
        driver: local
    graylog_journal:
        driver: local

The test project is a gradle project using this configuration:
plugins {
id “java”
id “org.springframework.boot” version “2.4.3”
id “io.spring.dependency-management” version “1.0.9.RELEASE”
}

group = ‘com.graylog’
version = ‘1.0.0-SNAPSHOT’

repositories {
mavenCentral()
}

configurations {
all*.exclude module : “spring-boot-starter-logging”
all*.exclude module : “log4j”
}

dependencies {
implementation “org.springframework.boot:spring-boot-starter-web”
implementation “org.apache.logging.log4j:log4j-api:2.14.1”
implementation “org.apache.logging.log4j:log4j-core:2.14.1”
implementation “org.slf4j:slf4j-api:1.7.9”
implementation “org.slf4j:slf4j-simple:1.7.9”
implementation “biz.paluch.logging:logstash-gelf:1.14.1”
// implementation “de.siegmar:logback-gelf:3.0.0”
}

The class:
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@RestController
public class LoggingController {

private final static Logger logger = LoggerFactory.getLogger(LoggingController.class);

@GetMapping("/add")
public String index() {
    logger.trace("A TRACE Message");
    logger.debug("A DEBUG Message");
    logger.info("An INFO Message");
    logger.warn("A WARN Message");
    logger.error("An ERROR Message");

    return "Howdy! Check out the Logs to see the output...";
}

}

Run and save in the graylog, so it works right.

In the project that I inherit they are using org.slf4j and I added logback-gelf dependencies. It now
is like this:

	<dependency>
		<groupId>org.slf4j</groupId>
		<artifactId>slf4j-api</artifactId>
	</dependency>
	<dependency>
		<groupId>org.slf4j</groupId>
		<artifactId>slf4j-simple</artifactId>
	</dependency>
	<dependency>
		<groupId>de.siegmar</groupId>
		<artifactId>logback-gelf</artifactId>
		<version>3.0.0</version>
	</dependency>

The logback.xml is the same in the test project as in real project:

<configuration debug="true">
    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
        <encoder>
            <pattern>%green(%date) %highlight(%-5level) %yellow([%-4relative]) %magenta([%thread]) %cyan(%logger{10}) %gray([%file:%line]) %blue(: %msg%n)</pattern>
            <charset>UTF-8</charset>
        </encoder>
    </appender>

    <appender name="GELF" class="de.siegmar.logbackgelf.GelfUdpAppender">
        <graylogHost>localhost</graylogHost>
        <graylogPort>12201</graylogPort>
    </appender>

    <!-- Use AsyncAppender to prevent slowdowns -->
    <appender name="ASYNC GELF" class="ch.qos.logback.classic.AsyncAppender">
        <appender-ref ref="GELF" />
    </appender>

    <root level="debug">
        <appender-ref ref="STDOUT" />
        <appender-ref ref="ASYNC GELF" />
    </root>

</configuration>

And the classes that log are like this:

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@ApplicationScoped
public class MyClassImpl implements MyClass {
  private static final Logger logger = LoggerFactory.getLogger(MyClassImpl.class);

  @Override
    public Response categories() {
        logger.info("getting categories in MyClassImpl");
        return Response.ok().entity(MyDAO.getCategories()).build();
    }

I run the real project and I see logs in console but not in the graylog. Also there is no error in the console.

I am thinking that I am missing in my configuration or doing wrong in my configuration but I can’t figure out what is because I duplicated dependencies and logback.xml file in 2 projects.
Any help is welcome.
Thanks.

Mariano

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.