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

Move logging to @ConfigMapping #42157

Merged
merged 1 commit into from
Oct 22, 2024
Merged
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package io.quarkus.deployment.configuration;

import java.util.List;
import java.util.Map;

import io.quarkus.runtime.LaunchMode;
import io.quarkus.runtime.console.ConsoleRuntimeConfig;
import io.quarkus.runtime.logging.LogBuildTimeConfig;
import io.quarkus.runtime.logging.LogRuntimeConfig;
import io.quarkus.runtime.logging.LoggingSetupRecorder;
import io.smallrye.config.SmallRyeConfigBuilder;
import io.smallrye.config.SmallRyeConfigBuilderCustomizer;

/**
* Even if the Log and Console mappings are marked as runtime, they are also used during build time.
* <p>
* We cannot register the mappings in the core runtime module because {@link io.smallrye.config.SmallRyeConfig}
* requires ASM to load the mappings. When we run a Quarkus test, Quarkus will generate the bytecode for the mappings,
* so we don't need ASM. In a non-Quarkus tests, ASM must be present in the classpath, which we want
* to avoid (even if they are in the test scope). The logging mappings shouldn't be loaded when running a non-Quarkus
* test because they are not required.
*
* @see LoggingSetupRecorder#initializeBuildTimeLogging(LogRuntimeConfig, LogBuildTimeConfig, ConsoleRuntimeConfig, Map, List,
* LaunchMode)
*/
public class BuildTimeConfigBuilderCustomizer implements SmallRyeConfigBuilderCustomizer {
@Override
public void configBuilder(final SmallRyeConfigBuilder builder) {
builder.withMapping(LogBuildTimeConfig.class)
.withMapping(LogRuntimeConfig.class)
.withMapping(ConsoleRuntimeConfig.class);
}
}
Original file line number Diff line number Diff line change
@@ -1,35 +1,45 @@
package io.quarkus.deployment.console;

import io.quarkus.runtime.annotations.ConfigItem;
import java.util.Optional;

import io.quarkus.runtime.annotations.ConfigPhase;
import io.quarkus.runtime.annotations.ConfigRoot;
import io.smallrye.config.ConfigMapping;
import io.smallrye.config.WithDefault;

/**
* Console
*/
@ConfigRoot
public class ConsoleConfig {

@ConfigMapping(prefix = "quarkus.console")
@ConfigRoot(phase = ConfigPhase.BUILD_TIME)
public interface ConsoleConfig {
/**
* If test results and status should be displayed in the console.
* <p>
* If this is false results can still be viewed in the dev console.
*/
@ConfigItem(defaultValue = "true")
public boolean enabled;
@WithDefault("true")
boolean enabled();

/**
* Disables the ability to enter input on the console.
*/
@ConfigItem(defaultValue = "false")
public boolean disableInput;
@WithDefault("false")
boolean disableInput();

/**
* Disable the testing status/prompt message at the bottom of the console
* and log these messages to STDOUT instead.
* <p>
* Use this option if your terminal does not support ANSI escape sequences.
*/
@ConfigItem(defaultValue = "false")
public boolean basic;
@WithDefault("false")
boolean basic();

/**
* If color should be enabled or disabled.
* <p>
* If this is not present then an attempt will be made to guess if the terminal supports color
*/
Optional<Boolean> color();
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,19 @@
import io.quarkus.deployment.dev.testing.TestConfig;
import io.quarkus.dev.console.BasicConsole;
import io.quarkus.dev.console.QuarkusConsole;
import io.quarkus.runtime.console.ConsoleRuntimeConfig;
import io.quarkus.runtime.util.ColorSupport;

public class ConsoleHelper {

public static synchronized void installConsole(TestConfig config, ConsoleConfig consoleConfig,
ConsoleRuntimeConfig consoleRuntimeConfig, io.quarkus.runtime.logging.ConsoleConfig logConfig, boolean test) {
public static synchronized void installConsole(TestConfig config, ConsoleConfig consoleConfig, boolean test) {
if (QuarkusConsole.installed) {
return;
}
boolean colorEnabled = ColorSupport.isColorEnabled(consoleRuntimeConfig, logConfig);
boolean colorEnabled = consoleConfig.color().orElse(QuarkusConsole.hasColorSupport());
QuarkusConsole.installed = true;
//if there is no color we need a basic console
//note that we never enable input for tests
//surefire communicates of stdin, so this can mess with it
boolean inputSupport = !test && !config.disableConsoleInput.orElse(consoleConfig.disableInput);
boolean inputSupport = !test && !config.disableConsoleInput.orElse(consoleConfig.disableInput());
if (!inputSupport) {
//note that in this case we don't hold onto anything from this class loader
//which is important for the test suite
Expand All @@ -37,7 +34,7 @@ public static synchronized void installConsole(TestConfig config, ConsoleConfig
new TerminalConnection(new Consumer<Connection>() {
@Override
public void accept(Connection connection) {
if (connection.supportsAnsi() && !config.basicConsole.orElse(consoleConfig.basic)) {
if (connection.supportsAnsi() && !config.basicConsole.orElse(consoleConfig.basic())) {
QuarkusConsole.INSTANCE = new AeshConsole(connection);
} else {
LinkedBlockingDeque<Integer> queue = new LinkedBlockingDeque<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import org.aesh.command.CommandException;
import org.aesh.command.CommandResult;
import org.aesh.command.invocation.CommandInvocation;
import org.eclipse.microprofile.config.ConfigProvider;
import org.jboss.logging.Logger;

import io.quarkus.deployment.Capabilities;
Expand All @@ -41,7 +40,6 @@
import io.quarkus.deployment.ide.EffectiveIdeBuildItem;
import io.quarkus.deployment.ide.Ide;
import io.quarkus.dev.console.QuarkusConsole;
import io.quarkus.runtime.console.ConsoleRuntimeConfig;

public class ConsoleProcessor {

Expand All @@ -59,25 +57,18 @@ public class ConsoleProcessor {
*/
@BuildStep(onlyIf = IsDevelopment.class)
@Produce(TestSetupBuildItem.class)
ConsoleInstalledBuildItem setupConsole(TestConfig config,
BuildProducer<TestListenerBuildItem> testListenerBuildItemBuildProducer,
LaunchModeBuildItem launchModeBuildItem, ConsoleConfig consoleConfig) {
ConsoleInstalledBuildItem setupConsole(
final TestConfig config,
final ConsoleConfig consoleConfig,
final LaunchModeBuildItem launchModeBuildItem,
final BuildProducer<TestListenerBuildItem> testListenerBuildItemBuildProducer) {

if (consoleInstalled) {
return ConsoleInstalledBuildItem.INSTANCE;
}
consoleInstalled = true;
if (config.console.orElse(consoleConfig.enabled)) {
//this is a bit of a hack, but we can't just inject this normally
//this is a runtime property value, but also a build time property value
//as when running in dev mode they are both basically equivalent
ConsoleRuntimeConfig consoleRuntimeConfig = new ConsoleRuntimeConfig();
consoleRuntimeConfig.color = ConfigProvider.getConfig().getOptionalValue("quarkus.console.color", Boolean.class);
io.quarkus.runtime.logging.ConsoleConfig loggingConsoleConfig = new io.quarkus.runtime.logging.ConsoleConfig();
loggingConsoleConfig.color = ConfigProvider.getConfig().getOptionalValue("quarkus.console.color",
Boolean.class);
ConsoleHelper.installConsole(config, consoleConfig, consoleRuntimeConfig, loggingConsoleConfig,
launchModeBuildItem.isTest());
if (config.console.orElse(consoleConfig.enabled())) {
ConsoleHelper.installConsole(config, consoleConfig, launchModeBuildItem.isTest());
ConsoleStateManager.init(QuarkusConsole.INSTANCE, launchModeBuildItem.getDevModeType().get());
//note that this bit needs to be refactored so it is no longer tied to continuous testing
if (TestSupport.instance().isEmpty() || config.continuousTesting == TestConfig.Mode.DISABLED
Expand Down
Loading
Loading