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
pull/35555/head
Phillip Webb 2 years ago
parent 022004d780
commit cf95ae92ea

@ -245,6 +245,8 @@ public class FlywayAutoConfiguration {
.to((prefix) -> configuration.scriptPlaceholderPrefix(prefix));
map.from(properties.getScriptPlaceholderSuffix())
.to((suffix) -> configuration.scriptPlaceholderSuffix(suffix));
map.from(properties.isExecuteInTransaction()).to(configuration::executeInTransaction);
map.from(properties::getLoggers).to(configuration::loggers);
// Flyway Teams properties
map.from(properties.getBatch()).to(configuration::batch);
map.from(properties.getDryRunOutput()).to(configuration::dryRunOutput);
@ -269,7 +271,6 @@ public class FlywayAutoConfiguration {
.as((patterns) -> patterns.toArray(new String[0]))
.to(configuration::ignoreMigrationPatterns);
map.from(properties.getDetectEncoding()).to(configuration::detectEncoding);
map.from(properties.isExecuteInTransaction()).to(configuration::executeInTransaction);
}
private void configureSqlServerKerberosLoginFile(FluentConfiguration configuration,

@ -367,6 +367,11 @@ public class FlywayProperties {
*/
private boolean executeInTransaction = true;
/**
* Loggers Flyway should use.
*/
private String[] loggers = { "slf4j" };
public boolean isEnabled() {
return this.enabled;
}
@ -855,4 +860,12 @@ public class FlywayProperties {
this.executeInTransaction = executeInTransaction;
}
public String[] getLoggers() {
return this.loggers;
}
public void setLoggers(String[] loggers) {
this.loggers = loggers;
}
}

@ -763,6 +763,21 @@ class FlywayAutoConfigurationTests {
.run((context) -> assertThat(context).hasSingleBean(ResourceProviderCustomizer.class));
}
@Test
void loggers() {
this.contextRunner.withUserConfiguration(EmbeddedDataSourceConfiguration.class)
.run((context) -> assertThat(context.getBean(Flyway.class).getConfiguration().getLoggers())
.containsExactly("slf4j"));
}
@Test
void overrideLoggers() {
this.contextRunner.withUserConfiguration(EmbeddedDataSourceConfiguration.class)
.withPropertyValues("spring.flyway.loggers=log4j2")
.run((context) -> assertThat(context.getBean(Flyway.class).getConfiguration().getLoggers())
.containsExactly("log4j2"));
}
@Test
void shouldRegisterResourceHints() {
RuntimeHints runtimeHints = new RuntimeHints();

Loading…
Cancel
Save