From 435fb770e04c88898139dd324ac8493f15c9554f Mon Sep 17 00:00:00 2001 From: George Gastaldi Date: Thu, 2 Jun 2022 16:35:19 -0300 Subject: [PATCH] Disable Websockets logging during native image build This gets rid of the following messages when building the native image: ``` 16:32:37,255 INFO [io.und.websockets] UT026004: Adding annotated client endpoint class io.quarkus.it.websocket.CodingClient 16:32:37,260 INFO [io.und.websockets] UT026003: Adding annotated server endpoint class io.quarkus.it.websocket.RecodingSocket for path /recoder 16:32:37,260 INFO [io.und.websockets] UT026003: Adding annotated server endpoint class io.quarkus.it.websocket.EchoSocket for path /echo 16:32:37,260 INFO [io.und.websockets] UT026003: Adding annotated server endpoint class io.quarkus.it.websocket.WebSocketOpenEndpoint for path /wsopen 16:32:37,367 INFO [io.und.websockets] UT026005: Adding programmatic server endpoint class io.quarkus.it.websocket.AddWebSocketHandler$WebSocketEndpoint for path /added-dynamic ``` --- .../runtime/DisableLoggingAutoFeature.java | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 extensions/websockets/client/runtime/src/main/java/io/quarkus/websockets/client/runtime/DisableLoggingAutoFeature.java diff --git a/extensions/websockets/client/runtime/src/main/java/io/quarkus/websockets/client/runtime/DisableLoggingAutoFeature.java b/extensions/websockets/client/runtime/src/main/java/io/quarkus/websockets/client/runtime/DisableLoggingAutoFeature.java new file mode 100644 index 0000000000000..fc275912582e7 --- /dev/null +++ b/extensions/websockets/client/runtime/src/main/java/io/quarkus/websockets/client/runtime/DisableLoggingAutoFeature.java @@ -0,0 +1,43 @@ +package io.quarkus.websockets.client.runtime; + +import java.util.HashMap; +import java.util.Map; +import java.util.logging.Level; +import java.util.logging.Logger; + +import org.graalvm.nativeimage.hosted.Feature; + +import com.oracle.svm.core.annotate.AutomaticFeature; + +/** + * Disables logging during the analysis phase + */ +@AutomaticFeature +public class DisableLoggingAutoFeature implements Feature { + + private static final String[] CATEGORIES = { + "io.undertow.websockets", + }; + + private final Map categoryMap = new HashMap<>(CATEGORIES.length); + + @Override + public void beforeAnalysis(BeforeAnalysisAccess access) { + for (String category : CATEGORIES) { + Logger logger = Logger.getLogger(category); + categoryMap.put(category, logger.getLevel()); + logger.setLevel(Level.WARNING); + } + } + + @Override + public void afterAnalysis(AfterAnalysisAccess access) { + for (String category : CATEGORIES) { + Level level = categoryMap.remove(category); + if (level != null) { + Logger logger = Logger.getLogger(category); + logger.setLevel(level); + } + } + } +}