From bc19e398ba3c7e710e0ef4786660cfc3ce3f7b5b Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Tue, 21 Feb 2023 16:10:26 +0000 Subject: [PATCH] Report Logback configuration errors when running in a native image Closes gh-34315 --- .../boot/logging/logback/LogbackLoggingSystem.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/logging/logback/LogbackLoggingSystem.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/logging/logback/LogbackLoggingSystem.java index 2e0e243f6f23..06d23ea47147 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/logging/logback/LogbackLoggingSystem.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/logging/logback/LogbackLoggingSystem.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2022 the original author or authors. + * Copyright 2012-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -207,7 +207,11 @@ private boolean initializeFromAotGeneratedArtifactsIfPossible(LoggingInitializat stopAndReset(loggerContext); SpringBootJoranConfigurator configurator = new SpringBootJoranConfigurator(initializationContext); configurator.setContext(loggerContext); - return configurator.configureUsingAotGeneratedArtifacts(); + boolean configuredUsingAotGeneratedArtifacts = configurator.configureUsingAotGeneratedArtifacts(); + if (configuredUsingAotGeneratedArtifacts) { + reportConfigurationErrorsIfNecessary(loggerContext); + } + return configuredUsingAotGeneratedArtifacts; } @Override @@ -241,6 +245,10 @@ protected void loadConfiguration(LoggingInitializationContext initializationCont catch (Exception ex) { throw new IllegalStateException("Could not initialize Logback logging from " + location, ex); } + reportConfigurationErrorsIfNecessary(loggerContext); + } + + private void reportConfigurationErrorsIfNecessary(LoggerContext loggerContext) { List statuses = loggerContext.getStatusManager().getCopyOfStatusList(); StringBuilder errors = new StringBuilder(); for (Status status : statuses) {