forked from flynn/flynn
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlog.go
39 lines (33 loc) · 853 Bytes
/
log.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package main
import (
"io"
"os"
"github.com/flynn/flynn/Godeps/_workspace/src/github.com/flynn/go-docopt"
"github.com/flynn/flynn/controller/client"
"github.com/flynn/flynn/pkg/cluster"
)
func init() {
register("log", runLog, `
usage: flynn log [options] <job>
Stream log for a specific job.
Options:
-s, --split-stderr send stderr lines to stderr
-f, --follow stream new lines after printing log buffer
`)
}
func runLog(args *docopt.Args, client *controller.Client) error {
rc, err := client.GetJobLog(mustApp(), args.String["<job>"], args.Bool["--follow"])
if err != nil {
return err
}
var stderr io.Writer = os.Stdout
if args.Bool["--split-stderr"] {
stderr = os.Stderr
}
attachClient := cluster.NewAttachClient(struct {
io.Writer
io.ReadCloser
}{nil, rc})
attachClient.Receive(os.Stdout, stderr)
return nil
}