github.com/tilt-dev/tilt@v0.36.0/internal/cli/logs.go (about) 1 package cli 2 3 import ( 4 "context" 5 "log" 6 "time" 7 8 "github.com/spf13/cobra" 9 10 "github.com/tilt-dev/tilt/internal/hud/server" 11 "github.com/tilt-dev/tilt/pkg/model" 12 13 "github.com/tilt-dev/tilt/internal/analytics" 14 ) 15 16 type logsCmd struct { 17 follow bool // if true, follow logs (otherwise print current logs and exit) 18 } 19 20 func (c *logsCmd) name() model.TiltSubcommand { return "logs" } 21 22 func (c *logsCmd) register() *cobra.Command { 23 cmd := &cobra.Command{ 24 Use: "logs [resource1, resource2...]", 25 DisableFlagsInUseLine: true, 26 Short: "Get logs from a running Tilt instance (optionally filtered for the specified resources)", 27 Long: `Get logs from a running Tilt instance (optionally filtered for the specified resources). 28 29 By default, looks for a running Tilt instance on localhost:10350 30 (this is configurable with the --port and --host flags). 31 `, 32 } 33 34 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.") 35 36 addConnectServerFlags(cmd) 37 addLogFilterFlags(cmd, "") 38 return cmd 39 } 40 41 func (c *logsCmd) run(ctx context.Context, args []string) error { 42 a := analytics.Get(ctx) 43 44 a.Incr("cmd.logs", nil) 45 defer a.Flush(time.Second) 46 47 if ok, reason := analytics.IsAnalyticsDisabledFromEnv(); ok { 48 log.Printf("Tilt analytics disabled: %s", reason) 49 } 50 51 // For `tilt logs`, the resources are passed as extra args. 52 logResourcesFlag = args 53 54 logDeps, err := wireLogsDeps(ctx, a, "logs") 55 if err != nil { 56 return err 57 } 58 59 return server.StreamLogs(ctx, c.follow, logDeps.url, logDeps.filter, logDeps.printer) 60 }