stack: add 'docker stack logs' command - #7282
Open
dlarochette wants to merge 1 commit into
Open
Conversation
Add a 'docker stack logs' subcommand that fetches the logs of all services in a stack and aggregates them into a single stream. Each line is prefixed with the name of the service it belongs to, colored per service (with --no-color to opt out), similar to what 'docker compose logs' does for compose projects. Supports the usual log options: --follow, --since, --tail, and --timestamps, which map directly to the service logs API. Signed-off-by: David LAROCHETTE <david.larochette@movesol.com>
dlarochette
requested review from
a team,
silvin-lubecki and
thaJeztah
as code owners
September 3, 2026 19:28
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What I did
Added a
docker stack logssubcommand that fetches the logs of all services in a stack and aggregates them into a single stream, with each line prefixed by the (colored) name of the service it belongs to — the swarm equivalent ofdocker compose logs.How I did it
ServiceListfiltered on thecom.docker.stack.namespacelabel (same filter as the other stack subcommands), erroring with the usualnothing found in stack:message when empty.ServiceLogs, demultiplexing the stream withstdcopy.StdCopyinto a small line-buffered prefix writer. A shared mutex keeps concurrent lines intact; partial writes are buffered until a newline so lines are never split.--no-colorto opt out. Prefixes are padded to the longest service name so output aligns.-f/--follow,--since,-n/--tail(per service),-t/--timestamps,--no-color— all mapping directly to the service logs API.How to verify it
Unit tests cover argument validation, API error propagation, option passthrough, output prefixing, and the line-buffering writer:
Verified manually on a 2-node swarm (services on both manager and worker):
--followstreams continuously;--timestampsand--sincebehave as fordocker service logs.Description for the changelog