Skip to content

Commit 0397c10

Browse files
authored
#263 Use AppLog.getLogger() rather than direct System.getLogger() for native-image (#265)
As per issue #263, when using GraalVM native-image using System.getLogger() directly is problematic for class initialisation. Using AppLog.getLogger() adds that one level of indirection that means we can successfully redirect the log messages to sl4j4-api and onto whatever backend is setup for that.
1 parent 7bc0dad commit 0397c10

File tree

12 files changed

+28
-10
lines changed

12 files changed

+28
-10
lines changed

avaje-jex-grizzly-spi/src/main/java/io/avaje/jex/grizzly/spi/GrizzlyHttpServer.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import java.util.concurrent.ExecutorService;
99
import java.util.concurrent.Executors;
1010

11+
import io.avaje.applog.AppLog;
1112
import org.glassfish.grizzly.http.server.HttpServer;
1213
import org.glassfish.grizzly.http.server.NetworkListener;
1314
import org.glassfish.grizzly.http.server.ServerConfiguration;
@@ -19,7 +20,7 @@
1920

2021
final class GrizzlyHttpServer extends com.sun.net.httpserver.HttpsServer {
2122
private static final System.Logger LOG =
22-
System.getLogger(GrizzlyHttpServer.class.getCanonicalName());
23+
AppLog.getLogger(GrizzlyHttpServer.class.getCanonicalName());
2324
private final HttpServer server;
2425
private InetSocketAddress addr;
2526
private ServerConfiguration httpConfiguration;

avaje-jex-grizzly-spi/src/main/java/module-info.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
requires static io.avaje.spi;
1414
requires static java.net.http;
15+
requires io.avaje.applog;
1516

16-
provides HttpServerProvider with io.avaje.jex.grizzly.spi.GrizzlyHttpServerProvider;
17+
provides HttpServerProvider with io.avaje.jex.grizzly.spi.GrizzlyHttpServerProvider;
1718
}

avaje-jex/pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@
1616

1717
<dependencies>
1818

19+
<dependency>
20+
<groupId>io.avaje</groupId>
21+
<artifactId>avaje-applog</artifactId>
22+
<version>1.0</version>
23+
</dependency>
24+
1925
<dependency>
2026
<groupId>io.avaje</groupId>
2127
<artifactId>avaje-config</artifactId>

avaje-jex/src/main/java/io/avaje/jex/DefaultLifecycle.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package io.avaje.jex;
22

3+
import io.avaje.applog.AppLog;
4+
35
import java.lang.System.Logger.Level;
46
import java.util.ArrayList;
57
import java.util.Collections;
@@ -10,7 +12,7 @@
1012

1113
final class DefaultLifecycle implements AppLifecycle {
1214

13-
private static final System.Logger log = System.getLogger("io.avaje.jex");
15+
private static final System.Logger log = AppLog.getLogger("io.avaje.jex");
1416

1517
private final List<Pair> shutdownRunnable = new ArrayList<>();
1618
private final ReentrantLock lock = new ReentrantLock();

avaje-jex/src/main/java/io/avaje/jex/core/BootstrapServer.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
import com.sun.net.httpserver.HttpServer;
1313

14+
import io.avaje.applog.AppLog;
1415
import io.avaje.jex.AppLifecycle;
1516
import io.avaje.jex.Jex;
1617
import io.avaje.jex.JexConfig;
@@ -21,7 +22,7 @@ public final class BootstrapServer {
2122

2223
private BootstrapServer() {}
2324

24-
private static final System.Logger log = System.getLogger("io.avaje.jex");
25+
private static final System.Logger log = AppLog.getLogger("io.avaje.jex");
2526

2627
public static Jex.Server start(Jex jex) {
2728
final var config = jex.config();

avaje-jex/src/main/java/io/avaje/jex/core/ExceptionManager.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import java.util.Map;
66

7+
import io.avaje.applog.AppLog;
78
import io.avaje.jex.http.HttpStatus;
89
import io.avaje.jex.http.Context;
910
import io.avaje.jex.http.ExceptionHandler;
@@ -14,7 +15,7 @@ final class ExceptionManager {
1415

1516
private static final String APPLICATION_JSON = "application/json";
1617

17-
private static final System.Logger log = System.getLogger("io.avaje.jex");
18+
private static final System.Logger log = AppLog.getLogger("io.avaje.jex");
1819

1920
private final Map<Class<?>, ExceptionHandler<?>> handlers;
2021

avaje-jex/src/main/java/io/avaje/jex/core/JdkJexServer.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@
44

55
import com.sun.net.httpserver.HttpServer;
66

7+
import io.avaje.applog.AppLog;
78
import io.avaje.jex.AppLifecycle;
89
import io.avaje.jex.Jex;
910

1011
final class JdkJexServer implements Jex.Server {
1112

12-
private static final System.Logger log = System.getLogger("io.avaje.jex");
13+
private static final System.Logger log = AppLog.getLogger("io.avaje.jex");
1314

1415
private final HttpServer server;
1516
private final AppLifecycle lifecycle;

avaje-jex/src/main/java/io/avaje/jex/core/ServiceManager.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import java.util.Map;
1515
import java.util.stream.Stream;
1616

17+
import io.avaje.applog.AppLog;
1718
import io.avaje.jex.Jex;
1819
import io.avaje.jex.Routing;
1920
import io.avaje.jex.compression.CompressedOutputStream;
@@ -28,7 +29,7 @@
2829
/** Core service methods available to Context implementations. */
2930
final class ServiceManager {
3031

31-
private static final System.Logger log = System.getLogger("io.avaje.jex");
32+
private static final System.Logger log = AppLog.getLogger("io.avaje.jex");
3233

3334
private final CompressionConfig compressionConfig;
3435
private final JsonService jsonService;

avaje-jex/src/main/java/io/avaje/jex/http/sse/SseClientImpl.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,13 @@
88
import java.util.concurrent.CompletableFuture;
99
import java.util.concurrent.atomic.AtomicBoolean;
1010

11+
import io.avaje.applog.AppLog;
1112
import io.avaje.jex.http.Context;
1213
import io.avaje.jex.spi.JsonService;
1314

1415
final class SseClientImpl implements SseClient {
1516

16-
private static final System.Logger log = System.getLogger(SseClient.class.getCanonicalName());
17+
private static final System.Logger log = AppLog.getLogger(SseClient.class.getCanonicalName());
1718

1819
private final AtomicBoolean terminated = new AtomicBoolean(false);
1920
private final Emitter emitter;

avaje-jex/src/main/java/io/avaje/jex/routes/Routes.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@
66
import java.util.concurrent.atomic.AtomicLong;
77
import java.util.concurrent.locks.LockSupport;
88

9+
import io.avaje.applog.AppLog;
910
import io.avaje.jex.Routing;
1011
import io.avaje.jex.http.HttpFilter;
1112

1213
final class Routes implements SpiRoutes {
1314

14-
private static final System.Logger log = System.getLogger("io.avaje.jex");
15+
private static final System.Logger log = AppLog.getLogger("io.avaje.jex");
1516

1617
/**
1718
* The "real" handlers by http method.

0 commit comments

Comments
 (0)