Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support to follow containers logs with DockerComposeContainer #158

Closed
mfuksa opened this issue Jun 15, 2016 · 5 comments
Closed

Add support to follow containers logs with DockerComposeContainer #158

mfuksa opened this issue Jun 15, 2016 · 5 comments

Comments

@mfuksa
Copy link

mfuksa commented Jun 15, 2016

When using DockerComposeContainer I would like to follow output logs from my containers that are started by DockerComposeContainer.

Maybe there is a way how to do it but I have not found it. Using DockerComposeContainer#followOutput(...)does not do that.
Thanks.

@rnorth
Copy link
Member

rnorth commented Jun 15, 2016

Hi Miroslav,

Yes, that feature doesn't exist yet. I'm currently doing quite a bit of
rework on docker compose support (#156) so I think it would make sense to
add this when that's all resolved - it should be easier then, as well.

I hope this is ok!
Thanks

Richard
On Wed, 15 Jun 2016 at 20:48, Miroslav Fuksa [email protected]
wrote:

When using DockerComposeContainer I would like to follow output logs from
my containers that are started by DockerComposeContainer.

Maybe there is a way how to do it but I have not found it. Using
DockerComposeContainer#followOutput(...)does not do that.
Thanks.


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
#158, or mute
the thread
https://github.com/notifications/unsubscribe/AAIET8qS7KiblwHbmXr4jCuF31mGoCshks5qL-aQgaJpZM4I2Rd_
.

Richard

@mfuksa
Copy link
Author

mfuksa commented Jun 15, 2016

Hi Richard,

no problem. I appreciate if it could be added (even later). I can access the logs other ways, so it's fine for me as a workaround.

Thanks a lot
Miroslav

@pcornish
Copy link

pcornish commented Aug 16, 2016

@mfuksa @rnorth

Something like this in DockerComposeContainer.createServices() might do it:

// tail child container logs
dockerClient.listContainersCmd()
        .withShowAll(true)
        .exec().stream()
        .filter(container -> Arrays.stream(container.getNames()).anyMatch(name -> name.startsWith("/" + identifier)))
        .forEach(container -> followOutput(
                container.getId(),
                new Slf4jLogConsumer(logger()).withPrefix(container.getNames()[0]),
                OutputFrame.OutputType.STDOUT, OutputFrame.OutputType.STDERR)
        );

// ...then

private void followOutput(String containerId, Consumer<OutputFrame> consumer, OutputFrame.OutputType... types) {
    LogContainerCmd cmd = dockerClient.logContainerCmd(containerId)
            .withFollowStream(true);

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

    cmd.exec(callback);
}

There are obvious DRY opportunities here, as this followOutput method is copy-pasta'd from GenericContainer, for illustrative purposes.

@outofcoffee
Copy link
Contributor

@rnorth we can probably close this now #233 has been merged.

@rnorth
Copy link
Member

rnorth commented Nov 20, 2016

Yep - released in 1.1.7 so will close.

@rnorth rnorth closed this as completed Nov 20, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants