-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19893 from stuartwdouglas/17808
Fix Dev UI Logging
- Loading branch information
Showing
16 changed files
with
410 additions
and
172 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
core/deployment/src/main/java/io/quarkus/deployment/console/ConsoleInstalledBuildItem.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package io.quarkus.deployment.console; | ||
|
||
import io.quarkus.builder.item.SimpleBuildItem; | ||
|
||
/** | ||
* Build item that signifies that the interactive console is ready. | ||
* | ||
* This will not always be present, as the console may not be installed | ||
*/ | ||
public final class ConsoleInstalledBuildItem extends SimpleBuildItem { | ||
|
||
public static final ConsoleInstalledBuildItem INSTANCE = new ConsoleInstalledBuildItem(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
core/deployment/src/main/java/io/quarkus/deployment/console/StartupLogCompressor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package io.quarkus.deployment.console; | ||
|
||
import java.io.Closeable; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Optional; | ||
import java.util.concurrent.atomic.AtomicInteger; | ||
import java.util.function.BiPredicate; | ||
|
||
import io.quarkus.deployment.dev.testing.MessageFormat; | ||
import io.quarkus.deployment.logging.LoggingSetupBuildItem; | ||
import io.quarkus.dev.console.QuarkusConsole; | ||
import io.quarkus.dev.console.StatusLine; | ||
|
||
/** | ||
* special filter that can be used to compress log messages to a status line | ||
* <p> | ||
* This is useful for Dev Services to show progress without cluttering up the logs | ||
*/ | ||
public class StartupLogCompressor implements Closeable, BiPredicate<String, Boolean> { | ||
|
||
final Thread thread; | ||
final String name; | ||
final StatusLine sl; | ||
final List<String> toDump = new ArrayList<>(); | ||
final AtomicInteger COUNTER = new AtomicInteger(); | ||
|
||
public StartupLogCompressor(String name, | ||
@SuppressWarnings("unused") Optional<ConsoleInstalledBuildItem> consoleInstalledBuildItem, | ||
@SuppressWarnings("unused") LoggingSetupBuildItem loggingSetupBuildItem) { | ||
if (QuarkusConsole.INSTANCE.isAnsiSupported()) { | ||
QuarkusConsole.installRedirects(); | ||
this.name = name; | ||
this.thread = Thread.currentThread(); | ||
QuarkusConsole.addOutputFilter(this); | ||
sl = QuarkusConsole.INSTANCE.registerStatusLine(1000 + COUNTER.incrementAndGet()); | ||
sl.setMessage(MessageFormat.BLUE + name + MessageFormat.RESET); | ||
} else { | ||
thread = null; | ||
this.name = null; | ||
sl = null; | ||
} | ||
} | ||
|
||
@Override | ||
public void close() { | ||
if (thread == null) { | ||
return; | ||
} | ||
QuarkusConsole.removeOutputFilter(this); | ||
sl.close(); | ||
} | ||
|
||
public void closeAndDumpCaptured() { | ||
if (thread == null) { | ||
return; | ||
} | ||
QuarkusConsole.removeOutputFilter(this); | ||
sl.close(); | ||
for (var i : toDump) { | ||
QuarkusConsole.INSTANCE.write(true, i); | ||
} | ||
} | ||
|
||
@Override | ||
public boolean test(String s, Boolean errorStream) { | ||
if (thread == null) { | ||
//not installed | ||
return true; | ||
} | ||
if (Thread.currentThread() == thread) { | ||
toDump.add(s); | ||
sl.setMessage(MessageFormat.BLUE + name + MessageFormat.RESET + " " + s.replace("\n", "")); | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.