Add logging to, and enable logging using SLF4J for, TestcontainersCassandraConfiguration.

This commit is contained in:
John Blum
2023-05-12 13:49:09 -07:00
parent 2a48c96257
commit 59a5d98526
2 changed files with 30 additions and 1 deletions

View File

@@ -19,6 +19,7 @@ import static org.assertj.core.api.Assertions.assertThat;
import java.net.InetSocketAddress;
import java.util.Arrays;
import java.util.Map;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.autoconfigure.cassandra.CassandraProperties;
@@ -33,6 +34,8 @@ import org.springframework.lang.NonNull;
import com.datastax.oss.driver.api.core.CqlSession;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testcontainers.containers.CassandraContainer;
import org.testcontainers.containers.GenericContainer;
import org.testcontainers.utility.DockerImageName;
@@ -68,6 +71,8 @@ public class TestcontainersCassandraConfiguration extends TestCassandraConfigura
private static final String TESTCONTAINERS_RYUK_DISABLED = "true";
private static final String TESTCONTAINERS_RYUK_ENABLED = "false";
private final Logger logger = LoggerFactory.getLogger(getClass());
@Bean("CassandraContainer")
GenericContainer<?> cassandraContainer(Environment environment) {
@@ -75,7 +80,29 @@ public class TestcontainersCassandraConfiguration extends TestCassandraConfigura
cassandraContainer.start();
return withCassandraServer(cassandraContainer, environment);
return logContainerConfiguration(withCassandraServer(cassandraContainer, environment));
}
protected @NonNull Logger getLogger() {
return this.logger;
}
protected void logInfo(String message, Object... arguments) {
Logger logger = getLogger();
if (logger.isInfoEnabled()) {
logger.info(message, arguments);
}
}
private @NonNull GenericContainer<?> logContainerConfiguration(@NonNull GenericContainer<?> cassandraContainer) {
logInfo("Cassandra Testcontainer Environment Configuration:");
cassandraContainer.getEnvMap().forEach((key, value) -> logInfo("{} = [{}]", key, value));
return cassandraContainer;
}
private @NonNull GenericContainer<?> newCassandraContainer() {

View File

@@ -17,6 +17,8 @@
<logger name="org.springframework" level="${logback.log.level:-ERROR}"/>
<logger name="example.app.crm.config.TestcontainersCassandraConfiguration" level="${logback.log.level:-INFO}"/>
<root level="${logback.log.level:-ERROR}">
<appender-ref ref="console"/>
</root>