/
system_logs.go
60 lines (52 loc) · 1.29 KB
/
system_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
58
59
60
// Copyright © 2017 Chef Software
package main
import (
"context"
"io"
"github.com/spf13/cobra"
api "github.com/chef/automate/api/interservice/deployment"
"github.com/chef/automate/components/automate-cli/pkg/docs"
"github.com/chef/automate/components/automate-cli/pkg/status"
"github.com/chef/automate/components/automate-deployment/pkg/client"
)
var systemLogsCmd = &cobra.Command{
Use: "system-logs",
Short: "Tail Chef Automate logs",
Long: "Start streaming logs from the Chef Automate server. Ctrl + c to stop.",
RunE: runSystemLogsCmd,
Annotations: map[string]string{
docs.Tag: docs.FrontEnd,
},
}
func runSystemLogsCmd(cmd *cobra.Command, args []string) error {
connection, err := client.Connection(client.DefaultClientTimeout)
if err != nil {
return err
}
stream, err := connection.SystemLogs(context.Background(), &api.SystemLogsRequest{})
if err != nil {
return status.Wrap(
err,
status.DeploymentServiceCallError,
"Request to get system logs failed",
)
}
for {
logLine, err := stream.Recv()
if err == io.EOF {
break
}
if err != nil {
return status.Wrap(
err,
status.DeploymentServiceCallError,
"Request to stream system logs failed",
)
}
writer.Print(logLine.Line)
}
return nil
}
func init() {
RootCmd.AddCommand(systemLogsCmd)
}