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