Browse code

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 authored on 2017/02/24 08:09:09
Showing 1 changed files
... ...
@@ -277,12 +277,22 @@ func (c *Cluster) ServiceLogs(ctx context.Context, input string, config *backend
277 277
 		return err
278 278
 	}
279 279
 
280
+	// set the streams we'll use
281
+	stdStreams := []swarmapi.LogStream{}
282
+	if config.ContainerLogsOptions.ShowStdout {
283
+		stdStreams = append(stdStreams, swarmapi.LogStreamStdout)
284
+	}
285
+	if config.ContainerLogsOptions.ShowStderr {
286
+		stdStreams = append(stdStreams, swarmapi.LogStreamStderr)
287
+	}
288
+
280 289
 	stream, err := state.logsClient.SubscribeLogs(ctx, &swarmapi.SubscribeLogsRequest{
281 290
 		Selector: &swarmapi.LogSelector{
282 291
 			ServiceIDs: []string{service.ID},
283 292
 		},
284 293
 		Options: &swarmapi.LogSubscriptionOptions{
285
-			Follow: config.Follow,
294
+			Follow:  config.Follow,
295
+			Streams: stdStreams,
286 296
 		},
287 297
 	})
288 298
 	if err != nil {