-
Notifications
You must be signed in to change notification settings - Fork 314
/
Copy pathlogs.go
57 lines (42 loc) · 1.51 KB
/
logs.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package cli
import (
"context"
"log"
"time"
"github.com/spf13/cobra"
"github.com/tilt-dev/tilt/internal/hud/server"
"github.com/tilt-dev/tilt/pkg/model"
"github.com/tilt-dev/tilt/internal/analytics"
)
type logsCmd struct {
follow bool // if true, follow logs (otherwise print current logs and exit)
}
func (c *logsCmd) name() model.TiltSubcommand { return "logs" }
func (c *logsCmd) register() *cobra.Command {
cmd := &cobra.Command{
Use: "logs [resource1, resource2...]",
DisableFlagsInUseLine: true,
Short: "Get logs from a running Tilt instance (optionally filtered for the specified resources)",
Long: `Get logs from a running Tilt instance (optionally filtered for the specified resources).
By default, looks for a running Tilt instance on localhost:10350
(this is configurable with the --port and --host flags).
`,
}
cmd.Flags().BoolVarP(&c.follow, "follow", "f", false, "If true, stream the requested logs; otherwise, print the requested logs at the current moment in time, then exit.")
// TODO: log level flags
addConnectServerFlags(cmd)
return cmd
}
func (c *logsCmd) run(ctx context.Context, args []string) error {
a := analytics.Get(ctx)
a.Incr("cmd.logs", nil)
defer a.Flush(time.Second)
if ok, reason := analytics.IsAnalyticsDisabledFromEnv(); ok {
log.Printf("Tilt analytics disabled: %s", reason)
}
logDeps, err := wireLogsDeps(ctx, a, "logs")
if err != nil {
return err
}
return server.StreamLogs(ctx, c.follow, logDeps.url, args, logDeps.printer)
}