Skip to content

Commit

Permalink
Update examples/logging/slf4j to use Nima (#6862)
Browse files Browse the repository at this point in the history
* Update examples/logging/slf4j to use Nima

Signed-off-by: aserkes <andrii.serkes@oracle.com>
  • Loading branch information
aserkes authored May 22, 2023
1 parent c2a11c8 commit b5b007e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 21 deletions.
6 changes: 3 additions & 3 deletions examples/logging/slf4j/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ The example can be built using GraalVM native image as well.
Expected output should be similar to the following (for both hotspot and native):
```text
15:40:44.240 INFO [main] i.h.examples.logging.slf4j.Main - Starting up startup
15:40:44.241 INFO [main] i.h.examples.logging.slf4j.Main - Using JUL logger startup
15:40:44.241 INFO [main] i.h.examples.logging.slf4j.Main - Using System logger startup
15:40:44.245 INFO [pool-1-thread-1] i.h.examples.logging.slf4j.Main - Running on another thread propagated
15:40:44.395 INFO [features-thread] io.helidon.common.features.HelidonFeatures - Helidon SE 2.2.0 features: [Config, WebServer]
15:40:44.538 INFO [nioEventLoopGroup-2-1] io.helidon.reactive.webserver.NettyWebServer - Channel '@default' started: [id: 0x8e516487, L:/0:0:0:0:0:0:0:0:8080]
15:40:44.395 INFO [features-thread] i.h.common.features.HelidonFeatures - Helidon NIMA 4.0.0-SNAPSHOT features: [Config, Encoding, Media, WebServer]
15:40:44.538 INFO [main] i.helidon.nima.webserver.LoomServer - Started all channels in 15 milliseconds. 561 milliseconds since JVM startup. Java 20.0.1+9-29 propagated
```

# Running as jar
Expand Down
4 changes: 2 additions & 2 deletions examples/logging/slf4j/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@

<dependencies>
<dependency>
<groupId>io.helidon.reactive.webserver</groupId>
<artifactId>helidon-reactive-webserver</artifactId>
<groupId>io.helidon.nima.webserver</groupId>
<artifactId>helidon-nima-webserver</artifactId>
</dependency>
<dependency>
<groupId>io.helidon.logging</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2020, 2022 Oracle and/or its affiliates.
* Copyright (c) 2020, 2023 Oracle and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -19,14 +19,13 @@
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;

import io.helidon.common.context.Context;
import io.helidon.common.context.Contexts;
import io.helidon.logging.common.HelidonMdc;
import io.helidon.logging.common.LogConfig;
import io.helidon.reactive.webserver.Routing;
import io.helidon.reactive.webserver.WebServer;
import io.helidon.nima.webserver.WebServer;
import io.helidon.nima.webserver.http.HttpRouting;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -55,18 +54,17 @@ public static void main(String[] args) {
// done by the webserver
Contexts.runInContext(Context.create(), Main::logging);

WebServer.builder()
.routing(Routing.builder()
.get("/", (req, res) -> {
HelidonMdc.set("name", String.valueOf(req.requestId()));
LOGGER.info("Running in webserver, id:");
res.send("Hello");
})
.build())
.port(8080)
.build()
.start()
.await(10, TimeUnit.SECONDS);
WebServer server = WebServer.builder()
.routing(Main::routing)
.start();
}

private static void routing(HttpRouting.Builder routing) {
routing.get("/", (req, res) -> {
HelidonMdc.set("name", String.valueOf(req.id()));
LOGGER.info("Running in webserver, id:");
res.send("Hello");
});
}

private static void logging() {
Expand Down

0 comments on commit b5b007e

Please sign in to comment.