github.com/moby/docker@v26.1.3+incompatible/client/task_logs.go (about) 1 package client // import "github.com/docker/docker/client" 2 3 import ( 4 "context" 5 "io" 6 "net/url" 7 "time" 8 9 "github.com/docker/docker/api/types/container" 10 timetypes "github.com/docker/docker/api/types/time" 11 ) 12 13 // TaskLogs returns the logs generated by a task in an io.ReadCloser. 14 // It's up to the caller to close the stream. 15 func (cli *Client) TaskLogs(ctx context.Context, taskID string, options container.LogsOptions) (io.ReadCloser, error) { 16 query := url.Values{} 17 if options.ShowStdout { 18 query.Set("stdout", "1") 19 } 20 21 if options.ShowStderr { 22 query.Set("stderr", "1") 23 } 24 25 if options.Since != "" { 26 ts, err := timetypes.GetTimestamp(options.Since, time.Now()) 27 if err != nil { 28 return nil, err 29 } 30 query.Set("since", ts) 31 } 32 33 if options.Timestamps { 34 query.Set("timestamps", "1") 35 } 36 37 if options.Details { 38 query.Set("details", "1") 39 } 40 41 if options.Follow { 42 query.Set("follow", "1") 43 } 44 query.Set("tail", options.Tail) 45 46 resp, err := cli.get(ctx, "/tasks/"+taskID+"/logs", query, nil) 47 if err != nil { 48 return nil, err 49 } 50 return resp.body, nil 51 }