File tree Expand file tree Collapse file tree 1 file changed +58
-0
lines changed
Expand file tree Collapse file tree 1 file changed +58
-0
lines changed Original file line number Diff line number Diff line change 1+ package cmd
2+
3+ import (
4+ "fmt"
5+ "io"
6+ "net/http"
7+ "net/url"
8+ "os"
9+
10+ "github.com/spf13/cobra"
11+ )
12+
13+ var logsCmd = & cobra.Command {
14+ Use : "logs" ,
15+ Short : "View proxy logs" ,
16+ Long : `View the request/process logs generated by your proxies. Logs can be filtered by proxy instance
17+ and/or date range. By default, logs are streamed in real-time.` ,
18+ RunE : func (cmd * cobra.Command , args []string ) error {
19+ proxy , err := cmd .Flags ().GetString ("proxy" )
20+ if err != nil {
21+ return err
22+ }
23+
24+ cmd .SilenceUsage = true
25+
26+ c , err := defaultAPIClient ()
27+ if err != nil {
28+ return err
29+ }
30+
31+ params := url.Values {}
32+ if proxy != "" {
33+ params .Add ("query" , fmt .Sprintf ("proxy=%q" , proxy ))
34+ }
35+
36+ resp , err := c .SendRequest (http .MethodGet , "/v1/logs?" + params .Encode (), nil )
37+ if err != nil {
38+ return err
39+ }
40+ defer resp .Body .Close ()
41+
42+ if resp .StatusCode != http .StatusOK {
43+ return fmt .Errorf ("unexpected status code: %d" , resp .StatusCode )
44+ }
45+
46+ _ , err = io .Copy (os .Stdout , resp .Body )
47+ if err != nil {
48+ return err
49+ }
50+
51+ return nil
52+ },
53+ }
54+
55+ func init () {
56+ logsCmd .PersistentFlags ().StringP ("proxy" , "p" , "" , "Proxy name" )
57+ rootCmd .AddCommand (logsCmd )
58+ }
You can’t perform that action at this time.
0 commit comments