Skip to content

Add support to follow containers logs with DockerComposeContainer #158

Closed

Description

@mfuksa

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.

Activity

  1. rnorth commented on Jun 15, 2016

    @rnorth
    Member

    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 notifications@github.com
    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

  2. mfuksa commented on Jun 15, 2016

    @mfuksa
    Author

    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

  3. pcornish commented on Aug 16, 2016

    @pcornish

    @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.

  4. modified the milestone: 1.1.7 on Nov 19, 2016
  5. outofcoffee commented on Nov 19, 2016

    @outofcoffee
    Contributor

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

  6. rnorth commented on Nov 20, 2016

    @rnorth
    Member

    Yep - released in 1.1.7 so will close.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions