log

package
v2.3.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 11, 2021 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Cmd = &cobra.Command{
	Use:     "log [cid]",
	Aliases: []string{"logs"},
	Short:   "Display logs for specified cid",
	Long:    `Display logs for specified cid`,
	Args:    cobra.ExactArgs(1),
	PreRun: func(cmd *cobra.Command, args []string) {
		err := viper.BindPFlags(cmd.Flags())
		c.CheckErr(err)
	},
	Run: func(cmd *cobra.Command, args []string) {
		opts := []client.WatchLogsOption{client.WithHistory(true)}
		jid := viper.GetString("jid")
		if jid != "" {
			opts = append(opts, client.WithJobIDFilter(jid))
		}

		ch := make(chan client.WatchLogsEvent)
		ctx, cancel := context.WithCancel(context.Background())
		defer cancel()

		err := c.PowClient.Data.WatchLogs(c.MustAuthCtx(ctx), ch, args[0], opts...)
		c.CheckErr(err)

		interrupt := make(chan os.Signal)
		signal.Notify(interrupt, os.Interrupt, syscall.SIGTERM)
		go func() {
			<-interrupt
			cancel()
			os.Exit(0)
		}()

		for {
			event, ok := <-ch
			if !ok {
				break
			}
			if event.Err != nil {
				c.Fatal(event.Err)
				break
			}
			ts := time.Unix(event.Res.LogEntry.Time, 0)
			c.Message("%v - %v", ts.Format("2006-01-02T15:04:05"), event.Res.LogEntry.Message)
		}
	},
}

Cmd is the command.

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL