From 33b408b74d2adce9c1d4f8a80a58e15a4b8f206b Mon Sep 17 00:00:00 2001 From: Georgios Andrianakis Date: Fri, 9 Sep 2022 10:14:45 +0300 Subject: [PATCH] Ensure that InitialConfigurator uses the Quarkus configured min log level This essentially prevents issues like https://github.com/quarkusio/quarkus/issues/27735 where a piece of Quarkus code executing very early in the startup sequence, would improperly determine the minimum logging level - i.e. ALL was used instead of the Quarkus build configured minimum level. --- .../logging/LoggingResourceProcessor.java | 24 +++++++++++++++++++ .../logging/InitialConfigurator.java | 20 +++++++++++++++- 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/core/deployment/src/main/java/io/quarkus/deployment/logging/LoggingResourceProcessor.java b/core/deployment/src/main/java/io/quarkus/deployment/logging/LoggingResourceProcessor.java index ea54927fc36ae..418af27f5bf1f 100644 --- a/core/deployment/src/main/java/io/quarkus/deployment/logging/LoggingResourceProcessor.java +++ b/core/deployment/src/main/java/io/quarkus/deployment/logging/LoggingResourceProcessor.java @@ -124,6 +124,30 @@ SystemPropertyBuildItem setProperty() { return new SystemPropertyBuildItem("java.util.logging.manager", "org.jboss.logmanager.LogManager"); } + // ensures that InitialConfigurator uses the build time configured minimum log level + @BuildStep + void setMinLevelForInitialConfigurator(LogBuildTimeConfig logBuildTimeConfig, + BuildProducer systemPropertyBuildItemBuildProducer, + BuildProducer nativeImageSystemPropertyBuildItemBuildProducer) { + Level effectiveMinLevel = logBuildTimeConfig.minLevel; + // go through the category config and if there exists a min-level lower than the root min-level, use it + for (CategoryBuildTimeConfig categoryBuildTimeConfig : logBuildTimeConfig.categories.values()) { + InheritableLevel inheritableLevel = categoryBuildTimeConfig.minLevel; + if (inheritableLevel.isInherited()) { + continue; + } + Level categoryMinLevel = inheritableLevel.getLevel(); + if (categoryMinLevel.intValue() < effectiveMinLevel.intValue()) { + effectiveMinLevel = categoryMinLevel; + } + } + String key = "logging.initial-configurator.min-level"; + String value = "" + effectiveMinLevel.intValue(); + systemPropertyBuildItemBuildProducer.produce(new SystemPropertyBuildItem(key, + value)); + nativeImageSystemPropertyBuildItemBuildProducer.produce(new NativeImageSystemPropertyBuildItem(key, value)); + } + @BuildStep void setUpDefaultLevels(List categories, Consumer configOutput, diff --git a/independent-projects/bootstrap/runner/src/main/java/io/quarkus/bootstrap/logging/InitialConfigurator.java b/independent-projects/bootstrap/runner/src/main/java/io/quarkus/bootstrap/logging/InitialConfigurator.java index f15c3d93c2c4e..f91ea6cc42536 100644 --- a/independent-projects/bootstrap/runner/src/main/java/io/quarkus/bootstrap/logging/InitialConfigurator.java +++ b/independent-projects/bootstrap/runner/src/main/java/io/quarkus/bootstrap/logging/InitialConfigurator.java @@ -13,10 +13,28 @@ public final class InitialConfigurator implements EmbeddedConfigurator { public static final QuarkusDelayedHandler DELAYED_HANDLER = new QuarkusDelayedHandler(); + private static final Level MIN_LEVEL; + + private static final String SYS_PROP_NAME = "logging.initial-configurator.min-level"; + + static { + Level minLevel = Level.ALL; + String minLevelSysProp = System.getProperty(SYS_PROP_NAME); + if (minLevelSysProp != null) { + try { + minLevel = Level.parse(minLevelSysProp); + } catch (IllegalArgumentException ignored) { + throw new IllegalArgumentException( + String.format("Unable to convert %s (obtained from the %s system property) into a known logging level.", + minLevelSysProp, SYS_PROP_NAME)); + } + } + MIN_LEVEL = minLevel; + } @Override public Level getMinimumLevelOf(final String loggerName) { - return Level.ALL; + return MIN_LEVEL; } @Override