Skip to content

Commit

Permalink
Merge pull request #19078 from phillip-kruger/logging-fix
Browse files Browse the repository at this point in the history
Move Dev UI Logging closer to Console logging
  • Loading branch information
phillip-kruger authored Jul 31, 2021
2 parents a285aac + a6ad04d commit 152586e
Show file tree
Hide file tree
Showing 11 changed files with 225 additions and 199 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package io.quarkus.deployment.builditem;

import java.util.Optional;
import java.util.logging.Handler;

import org.wildfly.common.Assert;

import io.quarkus.builder.item.SimpleBuildItem;
import io.quarkus.runtime.RuntimeValue;

/**
* A build item for adding the dev stream log
*/
public final class WebSocketLogHandlerBuildItem extends SimpleBuildItem {
private final RuntimeValue<Optional<Handler>> handlerValue;

/**
* Construct a new instance.
*
* @param handlerValue the handler value to add to the run time configuration
*/
public WebSocketLogHandlerBuildItem(final RuntimeValue<Optional<Handler>> handlerValue) {
this.handlerValue = Assert.checkNotNullParam("handlerValue", handlerValue);
}

/**
* Get the handler value.
*
* @return the handler value
*/
public RuntimeValue<Optional<Handler>> getHandlerValue() {
return handlerValue;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package io.quarkus.deployment.logging;

import io.quarkus.builder.item.MultiBuildItem;

public final class LogStreamBuildItem extends MultiBuildItem {
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import io.quarkus.deployment.builditem.NamedLogHandlersBuildItem;
import io.quarkus.deployment.builditem.RunTimeConfigurationDefaultBuildItem;
import io.quarkus.deployment.builditem.SystemPropertyBuildItem;
import io.quarkus.deployment.builditem.WebSocketLogHandlerBuildItem;
import io.quarkus.deployment.builditem.nativeimage.NativeImageSystemPropertyBuildItem;
import io.quarkus.deployment.builditem.nativeimage.RuntimeInitializedClassBuildItem;
import io.quarkus.deployment.builditem.nativeimage.ServiceProviderBuildItem;
Expand Down Expand Up @@ -145,9 +146,11 @@ void miscSetup(
@Record(ExecutionTime.RUNTIME_INIT)
LoggingSetupBuildItem setupLoggingRuntimeInit(LoggingSetupRecorder recorder, LogConfig log, LogBuildTimeConfig buildLog,
ConsoleRuntimeConfig consoleRuntimeConfig,
Optional<WebSocketLogHandlerBuildItem> logStreamHandlerBuildItem,
List<LogHandlerBuildItem> handlerBuildItems,
List<NamedLogHandlersBuildItem> namedHandlerBuildItems, List<LogConsoleFormatBuildItem> consoleFormatItems,
Optional<ConsoleFormatterBannerBuildItem> possibleBannerBuildItem,
List<LogStreamBuildItem> logStreamBuildItems,
LaunchModeBuildItem launchModeBuildItem,
List<LogCleanupFilterBuildItem> logCleanupFilters) {
if (!launchModeBuildItem.isAuxiliaryApplication()
Expand All @@ -166,7 +169,18 @@ LoggingSetupBuildItem setupLoggingRuntimeInit(LoggingSetupRecorder recorder, Log
if (bannerBuildItem != null) {
possibleSupplier = bannerBuildItem.getBannerSupplier();
}
recorder.initializeLogging(log, buildLog, consoleRuntimeConfig, handlers, namedHandlers,
// Dev UI Log Stream
RuntimeValue<Optional<Handler>> devUiLogHandler = null;
if (logStreamHandlerBuildItem.isPresent()) {
devUiLogHandler = logStreamHandlerBuildItem.get().getHandlerValue();
}
boolean alwaysEnableLogStream = false;
if (!logStreamBuildItems.isEmpty()) {
alwaysEnableLogStream = true;
}

recorder.initializeLogging(log, buildLog, consoleRuntimeConfig, alwaysEnableLogStream, devUiLogHandler, handlers,
namedHandlers,
consoleFormatItems.stream().map(LogConsoleFormatBuildItem::getFormatterValue).collect(Collectors.toList()),
possibleSupplier, launchModeBuildItem.getLaunchMode());
LogConfig logConfig = new LogConfig();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,16 @@ public static void handleFailedStart(RuntimeValue<Optional<Supplier<String>>> ba
ConfigInstantiator.handleObject(buildConfig);
ConsoleRuntimeConfig consoleRuntimeConfig = new ConsoleRuntimeConfig();
ConfigInstantiator.handleObject(consoleRuntimeConfig);
new LoggingSetupRecorder().initializeLogging(config, buildConfig, consoleRuntimeConfig, Collections.emptyList(),
new LoggingSetupRecorder().initializeLogging(config, buildConfig, consoleRuntimeConfig, false, null,
Collections.emptyList(),
Collections.emptyList(),
Collections.emptyList(), banner, LaunchMode.DEVELOPMENT);
}

public void initializeLogging(LogConfig config, LogBuildTimeConfig buildConfig,
ConsoleRuntimeConfig consoleConfig,
final boolean enableWebStream,
final RuntimeValue<Optional<Handler>> devUiConsoleHandler,
final List<RuntimeValue<Optional<Handler>>> additionalHandlers,
final List<RuntimeValue<Map<String, Handler>>> additionalNamedHandlers,
final List<RuntimeValue<Optional<Formatter>>> possibleFormatters,
Expand Down Expand Up @@ -128,6 +131,22 @@ public void accept(String loggerName, CleanupFilterConfig config) {
}
}

if ((launchMode.isDevOrTest() || enableWebStream)
&& devUiConsoleHandler != null
&& devUiConsoleHandler.getValue().isPresent()) {

Handler handler = devUiConsoleHandler.getValue().get();
handler.setErrorManager(errorManager);
handler.setFilter(new LogCleanupFilter(filterElements));

if (possibleBannerSupplier != null && possibleBannerSupplier.getValue().isPresent()) {
Supplier<String> bannerSupplier = possibleBannerSupplier.getValue().get();
String header = "\n" + bannerSupplier.get();
handler.publish(new LogRecord(Level.INFO, header));
}
handlers.add(handler);
}

if (!categories.isEmpty()) {
Map<String, Handler> namedHandlers = createNamedHandlers(config, consoleConfig, possibleFormatters, errorManager,
cleanupFiler, launchMode);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@
import io.quarkus.deployment.annotations.Record;
import io.quarkus.deployment.builditem.LaunchModeBuildItem;
import io.quarkus.deployment.builditem.LiveReloadBuildItem;
import io.quarkus.deployment.builditem.LogHandlerBuildItem;
import io.quarkus.deployment.builditem.ServiceStartBuildItem;
import io.quarkus.deployment.builditem.ShutdownContextBuildItem;
import io.quarkus.deployment.builditem.WebSocketLogHandlerBuildItem;
import io.quarkus.deployment.console.ConsoleCommand;
import io.quarkus.deployment.console.ConsoleStateManager;
import io.quarkus.deployment.ide.EffectiveIdeBuildItem;
Expand Down Expand Up @@ -100,8 +100,8 @@
import io.quarkus.vertx.http.runtime.devmode.DevConsoleRecorder;
import io.quarkus.vertx.http.runtime.devmode.RedirectHandler;
import io.quarkus.vertx.http.runtime.devmode.RuntimeDevConsoleRoute;
import io.quarkus.vertx.http.runtime.logstream.HistoryHandler;
import io.quarkus.vertx.http.runtime.logstream.LogStreamRecorder;
import io.quarkus.vertx.http.runtime.logstream.WebSocketLogHandler;
import io.vertx.core.Handler;
import io.vertx.core.Vertx;
import io.vertx.core.VertxOptions;
Expand Down Expand Up @@ -326,11 +326,13 @@ public void runtimeTemplates(List<DevConsoleRuntimeTemplateInfoBuildItem> items,

@BuildStep(onlyIf = IsDevelopment.class)
@Record(ExecutionTime.STATIC_INIT)
public HistoryHandlerBuildItem handler(BuildProducer<LogHandlerBuildItem> logHandlerBuildItemBuildProducer,
public void handler(BuildProducer<HistoryHandlerBuildItem> historyProducer,
BuildProducer<WebSocketLogHandlerBuildItem> webSocketLogHandlerBuildItem,
LogStreamRecorder recorder, DevUIConfig devUiConfig) {
RuntimeValue<Optional<HistoryHandler>> handler = recorder.handler(devUiConfig.historySize);
logHandlerBuildItemBuildProducer.produce(new LogHandlerBuildItem((RuntimeValue) handler));
return new HistoryHandlerBuildItem(handler);
RuntimeValue<Optional<WebSocketLogHandler>> handler = recorder.logHandler(devUiConfig.historySize);

webSocketLogHandlerBuildItem.produce(new WebSocketLogHandlerBuildItem((RuntimeValue) handler));
historyProducer.produce(new HistoryHandlerBuildItem(handler));
}

@Consume(LoggingSetupBuildItem.class)
Expand Down Expand Up @@ -788,9 +790,9 @@ public CompletionStage<Object> resolve(EvalContext context) {
}

public static final class HistoryHandlerBuildItem extends SimpleBuildItem {
final RuntimeValue<Optional<HistoryHandler>> value;
final RuntimeValue<Optional<WebSocketLogHandler>> value;

public HistoryHandlerBuildItem(RuntimeValue<Optional<HistoryHandler>> value) {
public HistoryHandlerBuildItem(RuntimeValue<Optional<WebSocketLogHandler>> value) {
this.value = value;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -563,12 +563,28 @@ function getThreadName(threadName, threadId) {

function getLogMessage(message){
if($('#logstreamColumnsModalMessageSwitch').is(":checked")){
// Make links clickable
if(message.includes("http://")){
message = makeLink(message, "http://");
}
if(message.includes("https://")){
message = makeLink(message, "https://");
}
// Make sure multi line is supported
if(message.includes('\n')){
var htmlifiedLines = [];
var lines = message.split('\n');
for (var i = 0; i < lines.length; i++) {
var line = lines[i];
line = line.replace(/ /g, '\u00a0');
if(i === lines.length-1){
htmlifiedLines.push(line);
}else{
htmlifiedLines.push(line + '<br/>');
}
}
message = htmlifiedLines.join('');
}
return message;
}
return "";
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@
@Recorder
public class LogStreamRecorder {

public RuntimeValue<Optional<HistoryHandler>> handler(int size) {
return new RuntimeValue<>(Optional.of(new HistoryHandler(size)));
public RuntimeValue<Optional<WebSocketLogHandler>> logHandler(int size) {
return new RuntimeValue<>(Optional.of(new WebSocketLogHandler(size)));
}

public Handler<RoutingContext> websocketHandler(RuntimeValue<Optional<HistoryHandler>> historyHandler) {
public Handler<RoutingContext> websocketHandler(RuntimeValue<Optional<WebSocketLogHandler>> handler) {
//we need to make sure this is created after logging
//is initialized, as it sets up a handler
return new LogStreamWebSocket(historyHandler.getValue().get());
return new LogStreamWebSocket(handler.getValue().get());
}
}
Loading

0 comments on commit 152586e

Please sign in to comment.