quarkusio / quarkus

Quarkus: Supersonic Subatomic Java.
https://quarkus.io
Apache License 2.0
13.73k stars 2.67k forks source link

Quarkus GELF Logging not working in Native Mode #35241

Open ericsouza opened 1 year ago

ericsouza commented 1 year ago

Describe the bug

Hi, I am trying to use quarkus and send logging to graylog using the kafka transport mechanism. It's all fine with JVM mode, but is not working after building and running the native binary.

Basically I created a new project using the quarkus CLI and added the logging-gelf extension, added the quarkus-kafka-client library and setup my appplication properties properly with the folling settings:

quarkus.http.port=9597
quarkus.http.test-port=9598
quarkus.devservices.enabled=false

quarkus.log.handler.gelf.enabled=true
quarkus.log.handler.gelf.host=kafka://localhost#quarkus-gelf-kafka
quarkus.log.handler.gelf.port=19092
quarkus.log.handler.gelf.facility=quarkus-gelf-kafka
quarkus.log.handler.gelf.include-full-mdc=true
quarkus.log.handler.gelf.origin-host=local
quarkus.log.handler.gelf.skip-hostname-resolution=true

Expected behavior

Expect native binary work as the JVM mode

Actual behavior

The application starts with message LogManager error of type WRITE_FAILURE: Could not send GELF message and no logs are sent to the kafka topic.

How to Reproduce?

I created an example project at my github with all the instructions in the README and a docker-compose.yaml to run kafka and kafka console ui: https://github.com/ericsouza/quarkus-gelf-kafka

But basically is just create a new quarkus project using the CLI

quarkus create app com.ericsouza:quarkus-gelf-kafka \
    --extension='resteasy-reactive'

Add the logging-gelf extension and the quarkus-kafka-client to the pom.xml:

<dependency>
      <groupId>io.quarkus</groupId>
      <artifactId>quarkus-logging-gelf</artifactId>
</dependency>
<dependency>
      <groupId>io.quarkus</groupId>
      <artifactId>quarkus-kafka-client</artifactId>
      <version>3.2.3.Final</version>
</dependency>

setup properties properly to work with kafka:

quarkus.devservices.enabled=false

quarkus.log.handler.gelf.enabled=true
quarkus.log.handler.gelf.host=kafka://localhost#quarkus-gelf-kafka
quarkus.log.handler.gelf.port=19092
quarkus.log.handler.gelf.facility=quarkus-gelf-kafka
quarkus.log.handler.gelf.include-full-mdc=true
quarkus.log.handler.gelf.origin-host=local
quarkus.log.handler.gelf.skip-hostname-resolution=true

after the # in the gelf host is the kafka topic name to send the logs

now you can call the /hello endpoint and see that in the jvm mode logs are produced correctly but in the native mode aren't.

Output of uname -a or ver

Linux pop-os 6.0.12-76060012-generic #202212290932~1674066459~20.04~3cd2bf3-Ubuntu SMP PREEMPT_DYNAMI x86_64 x86_64 x86_64 GNU/Linux

Output of java -version

openjdk version "17" 2021-09-14 OpenJDK Runtime Environment Temurin-17+35 (build 17+35) OpenJDK 64-Bit Server VM Temurin-17+35 (build 17+35, mixed mode, sharing)

GraalVM version (if different from Java)

None is installed

Quarkus version or git rev

3.2.3.Final

Build tool (ie. output of mvnw --version or gradlew --version)

Apache Maven 3.9.3

Additional information

No response

feczkob commented 3 months ago

Hey, connecting to this: I managed to overcome the slow satrtup using the configs from the other answer

quarkus.log.handler.gelf.origin-host=your-host-name-here
quarkus.log.handler.gelf.skip-hostname-resolution=true

However in dev mode the dev-ui does not load for me when I use gelf logging. Any idea why that is?

ericsouza commented 2 months ago

Hey, connecting to this: I managed to overcome the slow satrtup using the configs from the other answer

quarkus.log.handler.gelf.origin-host=your-host-name-here
quarkus.log.handler.gelf.skip-hostname-resolution=true

However in dev mode the dev-ui does not load for me when I use gelf logging. Any idea why that is?

After all I gave up on the idea of sending logs directly from quarkus to graylog. Now I'm logging as json to stdout using a custom log provider and collecting with fluentbit (or filebeat).

Be aware that the gelf library used by quarkus under the hood is now unmaintained