mirror of https://github.com/docker/cli.git
Add support for task and arbitrary combo logs
Refactored the API to more easily accept new endpoints. Added REST, client, and CLI endpoints for getting logs from a specific task. All that is needed after this commit to enable arbitrary service log selectors is a REST endpoint and handler. Task logs can be retrieved by putting in a task ID at the CLI instead of a service ID. Signed-off-by: Drew Erny <drew.erny@docker.com>
This commit is contained in:
parent
d99bce7b1c
commit
4dcceaf70e
|
@ -128,6 +128,7 @@ type ServiceAPIClient interface {
|
||||||
ServiceRemove(ctx context.Context, serviceID string) error
|
ServiceRemove(ctx context.Context, serviceID string) error
|
||||||
ServiceUpdate(ctx context.Context, serviceID string, version swarm.Version, service swarm.ServiceSpec, options types.ServiceUpdateOptions) (types.ServiceUpdateResponse, error)
|
ServiceUpdate(ctx context.Context, serviceID string, version swarm.Version, service swarm.ServiceSpec, options types.ServiceUpdateOptions) (types.ServiceUpdateResponse, error)
|
||||||
ServiceLogs(ctx context.Context, serviceID string, options types.ContainerLogsOptions) (io.ReadCloser, error)
|
ServiceLogs(ctx context.Context, serviceID string, options types.ContainerLogsOptions) (io.ReadCloser, error)
|
||||||
|
TaskLogs(ctx context.Context, taskID string, options types.ContainerLogsOptions) (io.ReadCloser, error)
|
||||||
TaskInspectWithRaw(ctx context.Context, taskID string) (swarm.Task, []byte, error)
|
TaskInspectWithRaw(ctx context.Context, taskID string) (swarm.Task, []byte, error)
|
||||||
TaskList(ctx context.Context, options types.TaskListOptions) ([]swarm.Task, error)
|
TaskList(ctx context.Context, options types.TaskListOptions) ([]swarm.Task, error)
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,52 @@
|
||||||
|
package client
|
||||||
|
|
||||||
|
import (
|
||||||
|
"io"
|
||||||
|
"net/url"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"golang.org/x/net/context"
|
||||||
|
|
||||||
|
"github.com/docker/docker/api/types"
|
||||||
|
timetypes "github.com/docker/docker/api/types/time"
|
||||||
|
)
|
||||||
|
|
||||||
|
// TaskLogs returns the logs generated by a task in an io.ReadCloser.
|
||||||
|
// It's up to the caller to close the stream.
|
||||||
|
func (cli *Client) TaskLogs(ctx context.Context, taskID string, options types.ContainerLogsOptions) (io.ReadCloser, error) {
|
||||||
|
query := url.Values{}
|
||||||
|
if options.ShowStdout {
|
||||||
|
query.Set("stdout", "1")
|
||||||
|
}
|
||||||
|
|
||||||
|
if options.ShowStderr {
|
||||||
|
query.Set("stderr", "1")
|
||||||
|
}
|
||||||
|
|
||||||
|
if options.Since != "" {
|
||||||
|
ts, err := timetypes.GetTimestamp(options.Since, time.Now())
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
query.Set("since", ts)
|
||||||
|
}
|
||||||
|
|
||||||
|
if options.Timestamps {
|
||||||
|
query.Set("timestamps", "1")
|
||||||
|
}
|
||||||
|
|
||||||
|
if options.Details {
|
||||||
|
query.Set("details", "1")
|
||||||
|
}
|
||||||
|
|
||||||
|
if options.Follow {
|
||||||
|
query.Set("follow", "1")
|
||||||
|
}
|
||||||
|
query.Set("tail", options.Tail)
|
||||||
|
|
||||||
|
resp, err := cli.get(ctx, "/tasks/"+taskID+"/logs", query, nil)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return resp.body, nil
|
||||||
|
}
|
Loading…
Reference in New Issue