Skip to content

Commit

Permalink
Add option to enable logging into stdout using env variable (#123)
Browse files Browse the repository at this point in the history
* Add option to log container into stdout

Signed-off-by: see-quick <maros.orsak159@gmail.com>

* update use only ENV variable

Signed-off-by: see-quick <maros.orsak159@gmail.com>

* remove un-necessary

Signed-off-by: see-quick <maros.orsak159@gmail.com>

* Add a few words into README.md

Signed-off-by: see-quick <maros.orsak159@gmail.com>

* oops

Signed-off-by: see-quick <maros.orsak159@gmail.com>

* update

Signed-off-by: see-quick <maros.orsak159@gmail.com>

---------

Signed-off-by: see-quick <maros.orsak159@gmail.com>
  • Loading branch information
see-quick authored Dec 17, 2024
1 parent cc69af4 commit b697d95
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ systemUnderTest.start();
strimziKafkaContainer.getProxy().setConnectionCut(true);
```

#### xi) Run a multi-node Kafka cluster
#### x) Run a multi-node Kafka cluster

To run a multi-node Kafka cluster, you can use the StrimziKafkaCluster class with the builder pattern.

Expand Down Expand Up @@ -235,6 +235,13 @@ StrimziKafkaCluster kafkaCluster = new StrimziKafkaCluster.StrimziKafkaClusterBu
kafkaCluster.start();
```

#### xi) Logging Kafka Container/Cluster Output to SLF4J

If you want to enable logging of the Kafka container’s output to SLF4J,
you can set the environment variable STRIMZI_TEST_CONTAINER_LOGGING_ENABLED to true.
By default, this feature is disabled.
This can help in debugging or monitoring the Kafka broker’s activities during tests.

### Running Mutation Testing

To run mutation testing and assess your code’s robustness against small changes, use the following Maven command:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.testcontainers.containers.GenericContainer;
import org.testcontainers.containers.Network;
import org.testcontainers.containers.ToxiproxyContainer;
import org.testcontainers.containers.output.Slf4jLogConsumer;
import org.testcontainers.containers.wait.strategy.Wait;
import org.testcontainers.containers.wait.strategy.WaitStrategy;
import org.testcontainers.images.builder.Transferable;
Expand Down Expand Up @@ -78,6 +79,8 @@ public class StrimziKafkaContainer extends GenericContainer<StrimziKafkaContaine
* Lazy image name provider
*/
private final CompletableFuture<String> imageNameProvider;
private final boolean enableBrokerContainerSlf4jLogging = Boolean.parseBoolean(
System.getenv().getOrDefault("STRIMZI_TEST_CONTAINER_LOGGING_ENABLED", "false"));

// instance attributes
private int kafkaExposedPort;
Expand Down Expand Up @@ -186,6 +189,10 @@ protected void doStart() {
this.addEnv("OAUTH_USERNAME_CLAIM", this.usernameClaim);
}

if (this.enableBrokerContainerSlf4jLogging) {
this.withLogConsumer(new Slf4jLogConsumer(LoggerFactory.getLogger("StrimziKafkaContainer-" + this.brokerId)));
}

super.setCommand("sh", "-c", runStarterScript());
super.doStart();
}
Expand Down

0 comments on commit b697d95

Please sign in to comment.