Skip to content

Commit

Permalink
Simplified Quarkus logging (#179)
Browse files Browse the repository at this point in the history
  • Loading branch information
wjglerum authored Oct 25, 2024
1 parent faddc2b commit 703f7d5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -57,7 +53,7 @@ DevServicesResultBuildItem setup(LaunchModeBuildItem launchMode, LiveReloadBuild
CuratedApplicationShutdownBuildItem shutdown, WireMockServerBuildTimeConfig config,
BuildProducer<ValidationErrorBuildItem> 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(
Expand All @@ -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();
}

Expand All @@ -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));
});
}
Expand All @@ -114,19 +110,19 @@ 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()));
}

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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<ConnectWireMock>, DevServicesContext.ContextAware {

private static final Logger LOGGER = Logger.getLogger(WireMockServerConnector.class);
WireMock wiremock;

@Override
Expand Down Expand Up @@ -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;
}
}

}

0 comments on commit 703f7d5

Please sign in to comment.