cli icon indicating copy to clipboard operation
cli copied to clipboard

Implement optional --stream=stdout|stderr for "docker logs" command

Open mcordova1967 opened this issue 3 years ago • 3 comments

Description

I think it would bring great benefit to being able to filter logs using "docker logs --stream=xxxx" in order to obtain only stderr or stdout if required, combined with any other filter set for this command (--since, --until, etc).

I think that the actual logs command might support it, but it has hardcoded both streams ShowStdout/ShowStderr:

` options := types.ContainerLogsOptions{ ShowStdout: true, ShowStderr: true, Since: opts.since, Until: opts.until, Timestamps: opts.timestamps, Follow: opts.follow, Tail: opts.tail, Details: opts.details, }

` Source:

Sadly there is no way to pass an option to set one of those options in false, it would be so useful and a very simple way to separate logs.

I am sorry if this has been discussed before in length, but I did search for this and could find it neither in open nor closed issues in this repository.

mcordova1967 avatar Aug 18 '22 19:08 mcordova1967

This could be useful - however it won't work with the tty containers (started with docker run -t ...). In tty containers stderr is the same stream as stdout, so effectively all logs are stored with stream=stdout.

vvoland avatar Aug 19 '22 07:08 vvoland

I agree it would be useful, particularly for less data to be served over the API. However the logs should already be split between stdout and stderr for your shell. So for instance if you only want stderr:

docker logs my_container > /dev/null

cpuguy83 avatar Aug 19 '22 17:08 cpuguy83

I resorted to the API using Python, to obtain all the stderr logs from all servers of a particular service "cluster_cpp" (I am using swarm/stack), and it was easier, and it can be redirected to a file.

import docker client = docker.from_env() for container in client.containers.list(): if "_cpp" in container.name: print(container.id[:12] + " " + container.name)

print("----------------------------------------------------------------") print(container.logs(stderr=True, stdout=False).decode('UTF-8'))

Thanks for your reply.

On Fri, Aug 19, 2022 at 1:27 PM Brian Goff @.***> wrote:

I agree it would be useful, particularly for less data to be served over the API. However the logs should already be split between stdout and stderr for your shell. So for instance if you only want stderr:

docker logs my_container > /dev/null

— Reply to this email directly, view it on GitHub https://github.com/docker/cli/issues/3745#issuecomment-1220917325, or unsubscribe https://github.com/notifications/unsubscribe-auth/AW34RAGHKNK4HGM5JSKPRYDVZ67XJANCNFSM566L4VSQ . You are receiving this because you authored the thread.Message ID: @.***>

--

  • Framework Dinámica Plataforma avanzada para desarrollo rápido de aplicaciones Web/SQL con Java EE y Eclipse http://www.martincordova.com

  • El BLOG de Dinámica: http://dinamicaframework.blogspot.com/

  • El Canal de Dinámica en Youtube: http://www.youtube.com/dinamicaframework

  • Facebook https://www.facebook.com/FrameworkDinamica

Martín Córdova y Asociados, C.A. J-31134803-4 / Caracas, Venezuela Cel: 58-424-2686639

mcordova1967 avatar Aug 19 '22 17:08 mcordova1967

We are closing the issue for the moment, as it feels like a corner case. If really needed people can use the API or use the above workaround.

We may include this in the future in our backlog if we see more demand.

bsousaa avatar Nov 24 '22 11:11 bsousaa