-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlog.go
More file actions
37 lines (29 loc) · 647 Bytes
/
Copy pathlog.go
File metadata and controls
37 lines (29 loc) · 647 Bytes
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
package cmd
import (
commandlog "github.com/EdmilsonESF/runcmds/internal/command_log"
"github.com/spf13/cobra"
)
var follow bool
var logCmd = &cobra.Command{
Use: "log",
Short: "Show command logs",
Run: func(cmd *cobra.Command, args []string) {
log(args)
},
}
func init() {
logCmd.Flags().BoolVarP(&follow, "follow", "f", false, "Continuously stream new log lines")
rootCmd.AddCommand(logCmd)
}
func log(args []string) {
s := commandlog.NewStore()
var l chan *commandlog.LogMessage
if len(args) > 0 {
l = s.StreamLogsByName(args, follow)
} else {
l = s.StreamAllLogs(follow)
}
for msg := range l {
msg.Print()
}
}