Skip to content

Commit

Permalink
Merge pull request #27826 from geoand/27735-followup
Browse files Browse the repository at this point in the history
Ensure that InitialConfigurator uses the Quarkus configured min log level
  • Loading branch information
geoand authored Sep 10, 2022
2 parents ea26f96 + 33b408b commit 68cad6a
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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<SystemPropertyBuildItem> systemPropertyBuildItemBuildProducer,
BuildProducer<NativeImageSystemPropertyBuildItem> 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<LogCategoryBuildItem> categories,
Consumer<RunTimeConfigurationDefaultBuildItem> configOutput,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 68cad6a

Please sign in to comment.