Ver código fonte

Fix service logs API to be able to specify stream

Before this change, doing service logs was just tossing the stream
selectors and always using the default (both streams). This change adds
a check for which streams the user wants and only includes those.

Fixes #31306

Signed-off-by: Drew Erny <drew.erny@docker.com>
Drew Erny 8 anos atrás
pai
commit
f63c62ce70
1 arquivos alterados com 11 adições e 1 exclusões
  1. 11 1
      daemon/cluster/services.go

+ 11 - 1
daemon/cluster/services.go

@@ -277,12 +277,22 @@ func (c *Cluster) ServiceLogs(ctx context.Context, input string, config *backend
 		return err
 		return err
 	}
 	}
 
 
+	// set the streams we'll use
+	stdStreams := []swarmapi.LogStream{}
+	if config.ContainerLogsOptions.ShowStdout {
+		stdStreams = append(stdStreams, swarmapi.LogStreamStdout)
+	}
+	if config.ContainerLogsOptions.ShowStderr {
+		stdStreams = append(stdStreams, swarmapi.LogStreamStderr)
+	}
+
 	stream, err := state.logsClient.SubscribeLogs(ctx, &swarmapi.SubscribeLogsRequest{
 	stream, err := state.logsClient.SubscribeLogs(ctx, &swarmapi.SubscribeLogsRequest{
 		Selector: &swarmapi.LogSelector{
 		Selector: &swarmapi.LogSelector{
 			ServiceIDs: []string{service.ID},
 			ServiceIDs: []string{service.ID},
 		},
 		},
 		Options: &swarmapi.LogSubscriptionOptions{
 		Options: &swarmapi.LogSubscriptionOptions{
-			Follow: config.Follow,
+			Follow:  config.Follow,
+			Streams: stdStreams,
 		},
 		},
 	})
 	})
 	if err != nil {
 	if err != nil {