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