2015-12-03 19:34:16 -05:00
|
|
|
package lib
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io"
|
|
|
|
"net/url"
|
|
|
|
"time"
|
|
|
|
|
2015-12-04 17:02:06 -05:00
|
|
|
"github.com/docker/docker/api/types"
|
2015-12-03 19:34:16 -05:00
|
|
|
"github.com/docker/docker/pkg/timeutils"
|
|
|
|
)
|
|
|
|
|
|
|
|
// ContainerLogs returns the logs generated by a container in an io.ReadCloser.
|
|
|
|
// It's up to the caller to close the stream.
|
2015-12-04 17:02:06 -05:00
|
|
|
func (cli *Client) ContainerLogs(options types.ContainerLogsOptions) (io.ReadCloser, error) {
|
2015-12-04 21:06:12 -05:00
|
|
|
query := url.Values{}
|
2015-12-03 19:34:16 -05:00
|
|
|
if options.ShowStdout {
|
|
|
|
query.Set("stdout", "1")
|
|
|
|
}
|
|
|
|
|
|
|
|
if options.ShowStderr {
|
|
|
|
query.Set("stderr", "1")
|
|
|
|
}
|
|
|
|
|
|
|
|
if options.Since != "" {
|
|
|
|
ts, err := timeutils.GetTimestamp(options.Since, time.Now())
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
query.Set("since", ts)
|
|
|
|
}
|
|
|
|
|
|
|
|
if options.Timestamps {
|
|
|
|
query.Set("timestamps", "1")
|
|
|
|
}
|
|
|
|
|
|
|
|
if options.Follow {
|
|
|
|
query.Set("follow", "1")
|
|
|
|
}
|
|
|
|
query.Set("tail", options.Tail)
|
|
|
|
|
2015-12-05 20:28:36 -05:00
|
|
|
resp, err := cli.get("/containers/"+options.ContainerID+"/logs", query, nil)
|
2015-12-03 19:34:16 -05:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return resp.body, nil
|
|
|
|
}
|