private static Closeable attachConsumer(
        DockerClient dockerClient,
        String containerId,
        Consumer<OutputFrame> consumer,
        boolean followStream,
        OutputFrame.OutputType... types
    ) {
        final LogContainerCmd cmd = dockerClient
            .logContainerCmd(containerId)
            .withFollowStream(followStream)
            .withSince(0);

        final FrameConsumerResultCallback callback = new FrameConsumerResultCallback();
        for (OutputFrame.OutputType type : types) {
            callback.addConsumer(type, consumer);
            if (type == OutputFrame.OutputType.STDOUT) {
                cmd.withStdOut(true);
            }
            if (type == OutputFrame.OutputType.STDERR) {
                cmd.withStdErr(true);
            }
        }

        return cmd.exec(callback);
    }
Retrieve all previous log outputs for a container of the specified type(s).

@param dockerClient a Docker client
@param containerId  container ID to attach to
@param types        types of {@link OutputFrame} to receive
@return all previous output frames (stdout/stderr being separated by newline characters)
core/src/main/java/org/testcontainers/utility/LogUtils.java