Skip to content

Commit c2a11c8

Browse files
authored
Update examples/logging/log4j to use Nima (helidon-io#6861)
* Update examples/logging/log4j to use Nima Signed-off-by: aserkes <andrii.serkes@oracle.com>
1 parent 831b987 commit c2a11c8

3 files changed

Lines changed: 19 additions & 22 deletions

File tree

examples/logging/log4j/README.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,11 @@ java -jar target/helidon-examples-logging-log4j.jar
2222

2323
Expected output should be similar to the following:
2424
```text
25-
2020-11-19 15:44:48,561 main INFO Registered Log4j as the java.util.logging.LogManager.
2625
15:44:48.596 INFO [main] io.helidon.examples.logging.log4j.Main - Starting up "startup"
27-
15:44:48.598 INFO [main] io.helidon.examples.logging.log4j.Main - Using JUL logger "startup"
26+
15:44:48.598 INFO [main] io.helidon.examples.logging.log4j.Main - Using System logger "startup"
2827
15:44:48.600 INFO [pool-2-thread-1] io.helidon.examples.logging.log4j.Main - Running on another thread "propagated"
29-
15:44:48.704 INFO [features-thread] io.helidon.common.features.HelidonFeatures - Helidon SE 2.2.0 features: [Config, WebServer] ""
30-
15:44:48.801 INFO [nioEventLoopGroup-2-1] io.helidon.reactive.webserver.NettyWebServer - Channel '@default' started: [id: 0xa215c23d, L:/0:0:0:0:0:0:0:0:8080] ""
28+
15:44:48.704 INFO [features-thread] io.helidon.common.features.HelidonFeatures - Helidon NIMA 4.0.0-SNAPSHOT features: [Config, Encoding, Media, WebServer] ""
29+
15:44:48.801 INFO [main] io.helidon.nima.webserver.LoomServer - Started all channels in 12 milliseconds. 746 milliseconds since JVM startup. Java 20.0.1+9-29 "propagated"
3130
```
3231

3332
# Running as native image

examples/logging/log4j/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@
4141

4242
<dependencies>
4343
<dependency>
44-
<groupId>io.helidon.reactive.webserver</groupId>
45-
<artifactId>helidon-reactive-webserver</artifactId>
44+
<groupId>io.helidon.nima.webserver</groupId>
45+
<artifactId>helidon-nima-webserver</artifactId>
4646
</dependency>
4747
<dependency>
4848
<groupId>io.helidon.logging</groupId>

examples/logging/log4j/src/main/java/io/helidon/examples/logging/log4j/Main.java

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2020, 2022 Oracle and/or its affiliates.
2+
* Copyright (c) 2020, 2023 Oracle and/or its affiliates.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -19,14 +19,13 @@
1919
import java.util.concurrent.ExecutorService;
2020
import java.util.concurrent.Executors;
2121
import java.util.concurrent.Future;
22-
import java.util.concurrent.TimeUnit;
2322

2423
import io.helidon.common.context.Context;
2524
import io.helidon.common.context.Contexts;
2625
import io.helidon.logging.common.HelidonMdc;
2726
import io.helidon.logging.common.LogConfig;
28-
import io.helidon.reactive.webserver.Routing;
29-
import io.helidon.reactive.webserver.WebServer;
27+
import io.helidon.nima.webserver.WebServer;
28+
import io.helidon.nima.webserver.http.HttpRouting;
3029

3130
import org.apache.logging.log4j.Level;
3231
import org.apache.logging.log4j.LogManager;
@@ -68,18 +67,17 @@ public static void main(String[] args) {
6867
// done by the webserver
6968
Contexts.runInContext(Context.create(), Main::logging);
7069

71-
WebServer.builder()
72-
.routing(Routing.builder()
73-
.get("/", (req, res) -> {
74-
HelidonMdc.set("name", String.valueOf(req.requestId()));
75-
logger.info("Running in webserver, id:");
76-
res.send("Hello");
77-
})
78-
.build())
79-
.port(8080)
80-
.build()
81-
.start()
82-
.await(10, TimeUnit.SECONDS);
70+
WebServer server = WebServer.builder()
71+
.routing(Main::routing)
72+
.start();
73+
}
74+
75+
private static void routing(HttpRouting.Builder routing) {
76+
routing.get("/", (req, res) -> {
77+
HelidonMdc.set("name", String.valueOf(req.id()));
78+
logger.info("Running in webserver, id:");
79+
res.send("Hello");
80+
});
8381
}
8482

8583
private static void logging() {

0 commit comments

Comments
 (0)