Skip to content

Commit cf95ae9

Browse files
committed
Allow flyway loggers to be configured and provide SLF4J default
Add `spring.flyway.loggers` property which can be used to configure Flyway loggers and has a default value of "slf4j". Closes gh-35158
1 parent 022004d commit cf95ae9

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/flyway/FlywayAutoConfiguration.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,8 @@ private void configureProperties(FluentConfiguration configuration, FlywayProper
245245
.to((prefix) -> configuration.scriptPlaceholderPrefix(prefix));
246246
map.from(properties.getScriptPlaceholderSuffix())
247247
.to((suffix) -> configuration.scriptPlaceholderSuffix(suffix));
248+
map.from(properties.isExecuteInTransaction()).to(configuration::executeInTransaction);
249+
map.from(properties::getLoggers).to(configuration::loggers);
248250
// Flyway Teams properties
249251
map.from(properties.getBatch()).to(configuration::batch);
250252
map.from(properties.getDryRunOutput()).to(configuration::dryRunOutput);
@@ -269,7 +271,6 @@ private void configureProperties(FluentConfiguration configuration, FlywayProper
269271
.as((patterns) -> patterns.toArray(new String[0]))
270272
.to(configuration::ignoreMigrationPatterns);
271273
map.from(properties.getDetectEncoding()).to(configuration::detectEncoding);
272-
map.from(properties.isExecuteInTransaction()).to(configuration::executeInTransaction);
273274
}
274275

275276
private void configureSqlServerKerberosLoginFile(FluentConfiguration configuration,

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/flyway/FlywayProperties.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,11 @@ public class FlywayProperties {
367367
*/
368368
private boolean executeInTransaction = true;
369369

370+
/**
371+
* Loggers Flyway should use.
372+
*/
373+
private String[] loggers = { "slf4j" };
374+
370375
public boolean isEnabled() {
371376
return this.enabled;
372377
}
@@ -855,4 +860,12 @@ public void setExecuteInTransaction(boolean executeInTransaction) {
855860
this.executeInTransaction = executeInTransaction;
856861
}
857862

863+
public String[] getLoggers() {
864+
return this.loggers;
865+
}
866+
867+
public void setLoggers(String[] loggers) {
868+
this.loggers = loggers;
869+
}
870+
858871
}

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/flyway/FlywayAutoConfigurationTests.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -763,6 +763,21 @@ void containsResourceProviderCustomizer() {
763763
.run((context) -> assertThat(context).hasSingleBean(ResourceProviderCustomizer.class));
764764
}
765765

766+
@Test
767+
void loggers() {
768+
this.contextRunner.withUserConfiguration(EmbeddedDataSourceConfiguration.class)
769+
.run((context) -> assertThat(context.getBean(Flyway.class).getConfiguration().getLoggers())
770+
.containsExactly("slf4j"));
771+
}
772+
773+
@Test
774+
void overrideLoggers() {
775+
this.contextRunner.withUserConfiguration(EmbeddedDataSourceConfiguration.class)
776+
.withPropertyValues("spring.flyway.loggers=log4j2")
777+
.run((context) -> assertThat(context.getBean(Flyway.class).getConfiguration().getLoggers())
778+
.containsExactly("log4j2"));
779+
}
780+
766781
@Test
767782
void shouldRegisterResourceHints() {
768783
RuntimeHints runtimeHints = new RuntimeHints();

0 commit comments

Comments
 (0)