Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding logs to Dev UI #161

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion deployment/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-reactive-deployment</artifactId>
<artifactId>quarkus-rest-deployment</artifactId>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package io.quarkiverse.wiremock.devservice;

import java.util.concurrent.SubmissionPublisher;
import java.util.logging.Handler;
import java.util.logging.LogRecord;

/**
* Publish Logs
*/
public class LogPublisher extends SubmissionPublisher<String> {

public void publishLog(String logMessage) {
this.submit(logMessage);
}

public static class LogHandler extends Handler {
private final LogPublisher logPublisher;

public LogHandler(LogPublisher logPublisher) {
this.logPublisher = logPublisher;
}

@Override
public void publish(LogRecord record) {
String message = record.getMessage();
logPublisher.publishLog(message);
}

@Override
public void flush() {
// No-op
}

@Override
public void close() throws SecurityException {
// No-op
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;
Expand All @@ -34,6 +35,7 @@
import io.quarkus.deployment.builditem.LiveReloadBuildItem;
import io.quarkus.deployment.dev.devservices.DevServiceDescriptionBuildItem;
import io.quarkus.deployment.dev.devservices.GlobalDevServicesConfig;
import io.quarkus.devui.spi.buildtime.FooterLogBuildItem;
import io.quarkus.runtime.configuration.ConfigurationException;

class WireMockServerProcessor {
Expand All @@ -54,7 +56,8 @@ FeatureBuildItem feature() {
@BuildStep(onlyIf = { WireMockServerEnabled.class, GlobalDevServicesConfig.Enabled.class })
DevServicesResultBuildItem setup(LaunchModeBuildItem launchMode, LiveReloadBuildItem liveReload,
CuratedApplicationShutdownBuildItem shutdown, WireMockServerBuildTimeConfig config,
BuildProducer<ValidationErrorBuildItem> configErrors) {
BuildProducer<ValidationErrorBuildItem> configErrors,
BuildProducer<FooterLogBuildItem> footerLogProducer) {

LOGGER.debugf("Quarkus launch mode [%s]", launchMode.getLaunchMode());

Expand All @@ -74,7 +77,13 @@ DevServicesResultBuildItem setup(LaunchModeBuildItem launchMode, LiveReloadBuild
}

if (devService == null) {
devService = startWireMockDevService(config);
if (launchMode.getLaunchMode().isDevOrTest()) {
LogPublisher logPublisher = new LogPublisher();
devService = startWireMockDevService(config, Optional.of(logPublisher));
footerLogProducer.produce(new FooterLogBuildItem("WireMock", () -> logPublisher));
} else {
devService = startWireMockDevService(config, Optional.empty());
}
}
return devService.toBuildItem();
}
Expand All @@ -98,7 +107,8 @@ void watchWireMockConfigFiles(WireMockServerBuildTimeConfig config,
}
}

private static RunningDevService startWireMockDevService(WireMockServerBuildTimeConfig config) {
private static RunningDevService startWireMockDevService(WireMockServerBuildTimeConfig config,
Optional<LogPublisher> logPublisher) {

final WireMockConfiguration configuration = options()
.globalTemplating(config.globalResponseTemplating())
Expand All @@ -113,6 +123,11 @@ private static RunningDevService startWireMockDevService(WireMockServerBuildTime
configuration.usingFilesUnderDirectory(config.effectiveFileMapping());
}

if (logPublisher.isPresent()) {
java.util.logging.Logger wireMockLogger = java.util.logging.Logger.getLogger("com.github.tomakehurst.wiremock");
wireMockLogger.addHandler(new LogPublisher.LogHandler(logPublisher.get()));
}

final WireMockServer server = new WireMockServer(configuration);
server.start();
LOGGER.debugf("WireMock server listening on port [%s]", server.port());
Expand Down
4 changes: 2 additions & 2 deletions integration-tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
<dependencies>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-reactive</artifactId>
<artifactId>quarkus-rest</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-rest-client-reactive</artifactId>
<artifactId>quarkus-rest-client</artifactId>
</dependency>
<dependency>
<groupId>io.quarkiverse.wiremock</groupId>
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<maven.compiler.release>17</maven.compiler.release>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<quarkus.version>3.8.5</quarkus.version>
<quarkus.version>999-SNAPSHOT</quarkus.version>
<wiremock.version>3.6.0</wiremock.version>
</properties>
<dependencyManagement>
Expand Down
Loading