From 348f2055bfb000633bb80e89bcf62ea037a5af0b Mon Sep 17 00:00:00 2001 From: Matthias Andreas Benkard Date: Sat, 15 Jan 2022 16:13:01 +0100 Subject: Add a Spring Boot example and integration code. Change-Id: Ia11dea607c74d9b4cc9a698e9ec92e930bd03f37 --- .../example/RandomNumberParameterProvider.java | 14 ++++++++ .../jsonlogging/example/RootResource.java | 37 ++++++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 examples/quarkus/src/main/java/eu/mulk/quarkus/googlecloud/jsonlogging/example/RandomNumberParameterProvider.java create mode 100644 examples/quarkus/src/main/java/eu/mulk/quarkus/googlecloud/jsonlogging/example/RootResource.java (limited to 'examples/quarkus/src/main/java/eu') diff --git a/examples/quarkus/src/main/java/eu/mulk/quarkus/googlecloud/jsonlogging/example/RandomNumberParameterProvider.java b/examples/quarkus/src/main/java/eu/mulk/quarkus/googlecloud/jsonlogging/example/RandomNumberParameterProvider.java new file mode 100644 index 0000000..7e4158c --- /dev/null +++ b/examples/quarkus/src/main/java/eu/mulk/quarkus/googlecloud/jsonlogging/example/RandomNumberParameterProvider.java @@ -0,0 +1,14 @@ +package eu.mulk.quarkus.googlecloud.jsonlogging.example; + +import eu.mulk.quarkus.googlecloud.jsonlogging.KeyValueParameter; +import eu.mulk.quarkus.googlecloud.jsonlogging.StructuredParameter; +import eu.mulk.quarkus.googlecloud.jsonlogging.StructuredParameterProvider; +import java.util.concurrent.ThreadLocalRandom; + +public class RandomNumberParameterProvider implements StructuredParameterProvider { + + @Override + public StructuredParameter getParameter() { + return KeyValueParameter.of("randomNumber", ThreadLocalRandom.current().nextInt()); + } +} diff --git a/examples/quarkus/src/main/java/eu/mulk/quarkus/googlecloud/jsonlogging/example/RootResource.java b/examples/quarkus/src/main/java/eu/mulk/quarkus/googlecloud/jsonlogging/example/RootResource.java new file mode 100644 index 0000000..90cd587 --- /dev/null +++ b/examples/quarkus/src/main/java/eu/mulk/quarkus/googlecloud/jsonlogging/example/RootResource.java @@ -0,0 +1,37 @@ +package eu.mulk.quarkus.googlecloud.jsonlogging.example; + +import eu.mulk.quarkus.googlecloud.jsonlogging.KeyValueParameter; +import eu.mulk.quarkus.googlecloud.jsonlogging.Label; +import javax.annotation.PostConstruct; +import javax.enterprise.context.ApplicationScoped; +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import org.jboss.logging.Logger; +import org.jboss.logging.MDC; + +@Produces("text/plain") +@Path("/") +@ApplicationScoped +public class RootResource { + + static final Logger log = Logger.getLogger(RootResource.class); + + @PostConstruct + public void init() { + log.warn("Hey!"); + } + + @GET + public String hello() { + MDC.put("requestMethod", "GET"); + log.infof( + "Hello %s.", + "Mulkiatsch", + KeyValueParameter.of("a", "b"), + Label.of("app", "foo"), + KeyValueParameter.of("version", 10)); + throw new IllegalStateException(); + // return "ok"; + } +} -- cgit v1.2.3