From 36a1dd90d5b87c3b41efc517d8a59f2bd3ba92d7 Mon Sep 17 00:00:00 2001 From: Fedor Dudinsky Date: Thu, 13 Jun 2024 12:09:08 +0200 Subject: [PATCH] QQE-673 | Cover max-length option for syslog logs Adds new module for working with syslogs, since jboss uses json logs which have less predictable size. Uses official image pof sylog-ng. Syslog-ng was chose over rsyslog and logstash because it supports syslog input and stdout output out of the box, without additional plugins. Required for https://issues.redhat.com/browse/QUARKUS-4531 --- README.md | 7 ++ logging/thirdparty/pom.xml | 19 ++++++ .../quarkus/ts/logging/jboss/LogResource.java | 59 +++++++++++++++++ .../src/main/resources/application.properties | 18 +++++ .../io/quarkus/ts/logging/jboss/SyslogIT.java | 66 +++++++++++++++++++ .../src/test/resources/syslog-ng.conf | 11 ++++ pom.xml | 1 + 7 files changed, 181 insertions(+) create mode 100644 logging/thirdparty/pom.xml create mode 100644 logging/thirdparty/src/main/java/io/quarkus/ts/logging/jboss/LogResource.java create mode 100644 logging/thirdparty/src/main/resources/application.properties create mode 100644 logging/thirdparty/src/test/java/io/quarkus/ts/logging/jboss/SyslogIT.java create mode 100644 logging/thirdparty/src/test/resources/syslog-ng.conf diff --git a/README.md b/README.md index c002a9184..3f72b76ab 100644 --- a/README.md +++ b/README.md @@ -475,6 +475,13 @@ Module that covers the logging functionality using JBoss Logging Manager. The fo - Inject a `Logger` instance using a custom category - Setting up the log level property for logger instances - Check default `quarkus.log.min-level` value +- +### `logging/thirdparty` + +Module that covers, that logging works with various third-party solutions. The following scenarios are covered: +- Check default `quarkus.log.min-level` value +- Syslog-type log (syslog-ng is used) +- Option `quarkus.log.syslog.max-length` filters messages, which are too big ### `sql-db/hibernate` diff --git a/logging/thirdparty/pom.xml b/logging/thirdparty/pom.xml new file mode 100644 index 000000000..6876836f4 --- /dev/null +++ b/logging/thirdparty/pom.xml @@ -0,0 +1,19 @@ + + + 4.0.0 + + io.quarkus.ts.qe + parent + 1.0.0-SNAPSHOT + ../.. + + logging-thridparty + jar + Quarkus QE TS: Logging: Third party + + + io.quarkus + quarkus-rest + + + diff --git a/logging/thirdparty/src/main/java/io/quarkus/ts/logging/jboss/LogResource.java b/logging/thirdparty/src/main/java/io/quarkus/ts/logging/jboss/LogResource.java new file mode 100644 index 000000000..1e62e47d8 --- /dev/null +++ b/logging/thirdparty/src/main/java/io/quarkus/ts/logging/jboss/LogResource.java @@ -0,0 +1,59 @@ +package io.quarkus.ts.logging.jboss; + +import jakarta.inject.Inject; +import jakarta.ws.rs.GET; +import jakarta.ws.rs.POST; +import jakarta.ws.rs.Path; +import jakarta.ws.rs.PathParam; +import jakarta.ws.rs.QueryParam; + +import org.jboss.logging.Logger; + +import io.quarkus.arc.log.LoggerName; + +@Path("/log") +public class LogResource { + + public static final String CUSTOM_CATEGORY = "FOO"; + + private static final Logger LOG = Logger.getLogger(LogResource.class); + + @Inject + Logger log; + + @LoggerName(CUSTOM_CATEGORY) + Logger customCategoryLog; + + @POST + @Path("/static/{level}") + public void addLogMessageInStaticLogger(@PathParam("level") String level, @QueryParam("message") String message) { + addLogMessage(LOG, level, message); + } + + @POST + @Path("/field/{level}") + public void addLogMessageInFieldLogger(@PathParam("level") String level, @QueryParam("message") String message) { + addLogMessage(log, level, message); + } + + @POST + @Path("/field-with-custom-category/{level}") + public void addLogMessageInFieldWithCustomCategoryLogger(@PathParam("level") String level, + @QueryParam("message") String message) { + addLogMessage(customCategoryLog, level, message); + } + + @GET + public void logExample() { + LOG.fatal("Fatal log example"); + LOG.error("Error log example"); + LOG.warn("Warn log example"); + LOG.info("Info log example"); + LOG.debug("Debug log example"); + LOG.trace("Trace log example"); + } + + private void addLogMessage(Logger logger, String level, String message) { + logger.log(Logger.Level.valueOf(level.toUpperCase()), message); + } +} diff --git a/logging/thirdparty/src/main/resources/application.properties b/logging/thirdparty/src/main/resources/application.properties new file mode 100644 index 000000000..bfdd6662f --- /dev/null +++ b/logging/thirdparty/src/main/resources/application.properties @@ -0,0 +1,18 @@ +#When you set the logging level below the minimum logging level, you must adjust the minimum logging level as well. +#Otherwise, the value of minimum logging level overrides the logging level. +# DOC: +# https://access.redhat.com/documentation/en-us/red_hat_build_of_quarkus/1.11/html-single/configuring_logging_with_quarkus/index#ref-example-logging-configuration_quarkus-configuring-logging +# https://quarkus.io/guides/logging +# https://quarkus.io/guides/all-config#quarkus-core_quarkus.log.min-level + +# By default min-level is set to DEBUG +#quarkus.log.min-level=DEBUG +quarkus.log.level=INFO + +%syslog.quarkus.log.syslog.enable=true +%syslog.quarkus.log.syslog.app-name=quarkus +%syslog.quarkus.log.syslog.format=%-5p %s%n +%syslog.quarkus.log.syslog.syslog-type=rfc3164 +%syslog.quarkus.log.syslog.protocol=tcp +# the option below is overriden in @QuarkusScenario tests +%syslog.quarkus.log.syslog.endpoint=localhost:1514 diff --git a/logging/thirdparty/src/test/java/io/quarkus/ts/logging/jboss/SyslogIT.java b/logging/thirdparty/src/test/java/io/quarkus/ts/logging/jboss/SyslogIT.java new file mode 100644 index 000000000..6a01f569a --- /dev/null +++ b/logging/thirdparty/src/test/java/io/quarkus/ts/logging/jboss/SyslogIT.java @@ -0,0 +1,66 @@ +package io.quarkus.ts.logging.jboss; + +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; + +import io.quarkus.test.bootstrap.RestService; +import io.quarkus.test.scenarios.QuarkusScenario; +import io.quarkus.test.services.Container; +import io.quarkus.test.services.QuarkusApplication; + +@QuarkusScenario +public class SyslogIT { + + /* + * For manual testing: + * podman run -p 8514:514 \ + * -v $(pwd)/src/test/resources/syslog-ng.conf:/etc/syslog-ng/syslog-ng.conf:z --rm -it balabit/syslog-ng + */ + @Container(image = "balabit/syslog-ng", port = 514, expectedLog = "syslog-ng") + static RestService syslog = new RestService() + .withProperty("_ignored", "resource_with_destination::/etc/syslog-ng/|syslog-ng.conf"); + + @QuarkusApplication + static RestService app = new RestService() + .withProperty("quarkus.profile", "syslog") + .withProperty("quarkus.log.syslog.max-length", "64") + .withProperty("quarkus.log.syslog.endpoint", () -> syslog.getURI().toString()); + + @Test + public void checkDefaultLogMinLevel() { + app.given().when().get("/log").then().statusCode(204); + + syslog.logs().assertContains("Fatal log example"); + + syslog.logs().assertContains("Error log example"); + syslog.logs().assertContains("Warn log example"); + syslog.logs().assertContains("Info log example"); + + // the value of minimum logging level overrides the logging level + syslog.logs().assertDoesNotContain("Debug log example"); + syslog.logs().assertDoesNotContain("Trace log example"); + } + + @Test + @Tag("https://issues.redhat.com/browse/QUARKUS-4531") + public void logBigMessage() { + String shorterMessage = "Relatively long message"; + app.given().when() + .post("/log/static/info?message={message}", shorterMessage) + .then().statusCode(204); + syslog.logs().assertContains(shorterMessage); + } + + @Test + @Tag("https://issues.redhat.com/browse/QUARKUS-4531") + public void filterBigMessage() { + String longerMessage = "Message, which is very long and is not expected to fit into 64 bytes"; + app.given().when() + .post("/log/static/info?message={message}", + longerMessage) + .then().statusCode(204); + + syslog.logs().assertDoesNotContain(longerMessage); + } + +} diff --git a/logging/thirdparty/src/test/resources/syslog-ng.conf b/logging/thirdparty/src/test/resources/syslog-ng.conf new file mode 100644 index 000000000..e23c3e6b7 --- /dev/null +++ b/logging/thirdparty/src/test/resources/syslog-ng.conf @@ -0,0 +1,11 @@ +@version: 4.4 +@include "scl.conf" + +log { + source { + #network(); + tcp(ip(0.0.0.0) port(514)); + }; + #destination { file("/var/log/syslog"); }; + destination {stdout();}; +}; \ No newline at end of file diff --git a/pom.xml b/pom.xml index 4d7b80990..c18e6114f 100644 --- a/pom.xml +++ b/pom.xml @@ -418,6 +418,7 @@ super-size/many-extensions quarkus-cli logging/jboss + logging/thirdparty qute/multimodule qute/synchronous qute/reactive