From 8dd2d817eb280712ff1ab3f476a229af597dfdc7 Mon Sep 17 00:00:00 2001 From: Willem Jan Glerum Date: Fri, 25 Oct 2024 14:47:21 +0200 Subject: [PATCH] Simplified Quarkus logging https://quarkus.io/guides/logging#simplified-logging --- .../devservice/WireMockServerProcessor.java | 22 ++++++++----------- .../devservice/WireMockServerConnector.java | 7 ++---- 2 files changed, 11 insertions(+), 18 deletions(-) diff --git a/deployment/src/main/java/io/quarkiverse/wiremock/devservice/WireMockServerProcessor.java b/deployment/src/main/java/io/quarkiverse/wiremock/devservice/WireMockServerProcessor.java index 1052af3..c59a364 100644 --- a/deployment/src/main/java/io/quarkiverse/wiremock/devservice/WireMockServerProcessor.java +++ b/deployment/src/main/java/io/quarkiverse/wiremock/devservice/WireMockServerProcessor.java @@ -26,19 +26,15 @@ import io.quarkus.deployment.annotations.BuildProducer; import io.quarkus.deployment.annotations.BuildStep; import io.quarkus.deployment.annotations.Consume; -import io.quarkus.deployment.builditem.CuratedApplicationShutdownBuildItem; -import io.quarkus.deployment.builditem.DevServicesResultBuildItem; +import io.quarkus.deployment.builditem.*; import io.quarkus.deployment.builditem.DevServicesResultBuildItem.RunningDevService; -import io.quarkus.deployment.builditem.FeatureBuildItem; -import io.quarkus.deployment.builditem.HotDeploymentWatchedFileBuildItem; -import io.quarkus.deployment.builditem.LaunchModeBuildItem; -import io.quarkus.deployment.builditem.LiveReloadBuildItem; import io.quarkus.deployment.dev.devservices.DevServiceDescriptionBuildItem; import io.quarkus.deployment.dev.devservices.GlobalDevServicesConfig; +import io.quarkus.logging.Log; import io.quarkus.runtime.configuration.ConfigurationException; class WireMockServerProcessor { - private static final Logger LOGGER = Logger.getLogger(WireMockServerProcessor.class); + private static final String FEATURE_NAME = "wiremock"; private static final String DEV_SERVICE_NAME = "WireMock"; private static final String MAPPINGS = "mappings"; @@ -57,7 +53,7 @@ DevServicesResultBuildItem setup(LaunchModeBuildItem launchMode, LiveReloadBuild CuratedApplicationShutdownBuildItem shutdown, WireMockServerBuildTimeConfig config, BuildProducer configErrors) { - LOGGER.debugf("Quarkus launch mode [%s]", launchMode.getLaunchMode()); + Log.debugf("Quarkus launch mode [%s]", launchMode.getLaunchMode()); if (isPortConfigInvalid(config)) { configErrors.produce(new ValidationErrorBuildItem(new ConfigurationException( @@ -70,7 +66,7 @@ DevServicesResultBuildItem setup(LaunchModeBuildItem launchMode, LiveReloadBuild shutdown.addCloseTask(WireMockServerProcessor::stopWireMockDevService, true); if (liveReload.isLiveReload() && config.reload()) { - LOGGER.debug("Live reload triggered!"); + Log.debug("Live reload triggered!"); stopWireMockDevService(); } @@ -93,7 +89,7 @@ void watchWireMockConfigFiles(WireMockServerBuildTimeConfig config, if (!config.isClasspathFilesMapping()) { listFiles(Paths.get(config.effectiveFileMapping(), MAPPINGS), Paths.get(config.effectiveFileMapping(), FILES)).forEach(file -> { - LOGGER.debugf("Watching [%s] for hot deployment!", file); + Log.debugf("Watching [%s] for hot deployment!", file); items.produce(new HotDeploymentWatchedFileBuildItem(file)); }); } @@ -114,7 +110,7 @@ private static RunningDevService startWireMockDevService(WireMockServerBuildTime final WireMockServer server = new WireMockServer(configuration); server.start(); - LOGGER.debugf("WireMock server listening on port [%s]", server.port()); + Log.debugf("WireMock server listening on port [%s]", server.port()); return new RunningDevService(DEV_SERVICE_NAME, null, server::shutdown, PORT, String.valueOf(server.port())); } @@ -122,11 +118,11 @@ private static RunningDevService startWireMockDevService(WireMockServerBuildTime private static synchronized void stopWireMockDevService() { try { if (devService != null) { - LOGGER.debugf("Stopping WireMock server running on port %s", devService.getConfig().get(PORT)); + Log.debugf("Stopping WireMock server running on port %s", devService.getConfig().get(PORT)); devService.close(); } } catch (IOException e) { - LOGGER.error("Failed to stop WireMock server", e); + Log.error("Failed to stop WireMock server", e); throw new UncheckedIOException(e); } finally { devService = null; diff --git a/test/src/main/java/io/quarkiverse/wiremock/devservice/WireMockServerConnector.java b/test/src/main/java/io/quarkiverse/wiremock/devservice/WireMockServerConnector.java index 82df5b6..b6678cd 100644 --- a/test/src/main/java/io/quarkiverse/wiremock/devservice/WireMockServerConnector.java +++ b/test/src/main/java/io/quarkiverse/wiremock/devservice/WireMockServerConnector.java @@ -5,17 +5,15 @@ import java.util.Collections; import java.util.Map; -import org.jboss.logging.Logger; - import com.github.tomakehurst.wiremock.client.WireMock; +import io.quarkus.logging.Log; import io.quarkus.test.common.DevServicesContext; import io.quarkus.test.common.QuarkusTestResourceConfigurableLifecycleManager; public class WireMockServerConnector implements QuarkusTestResourceConfigurableLifecycleManager, DevServicesContext.ContextAware { - private static final Logger LOGGER = Logger.getLogger(WireMockServerConnector.class); WireMock wiremock; @Override @@ -43,9 +41,8 @@ public void setIntegrationTestContext(DevServicesContext context) { wiremock = new WireMock(port); wiremock.getGlobalSettings(); // establish a connection to WireMock server eagerly } catch (Exception ex) { - LOGGER.error("Cannot connect to WireMock server!", ex); + Log.error("Cannot connect to WireMock server!", ex); throw ex; } } - }