forked from remind101/empire
-
Notifications
You must be signed in to change notification settings - Fork 0
/
log.go
63 lines (50 loc) · 1.09 KB
/
log.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
61
62
63
package main
import (
"fmt"
"os"
"time"
)
var duration string
var cmdLog = &Command{
Run: runLog,
Usage: "log [-d]",
NeedsApp: true,
Category: "app",
Short: "stream app log lines",
Long: `
Log prints the streaming application log.
Options:
-d duration to go back and start reading logs from (ie. 10m will start
streaming from 10 minutes ago)
Examples:
$ emp log -a acme-inc
2013-10-17T00:17:35.066089+00:00 app[web.1]: Completed 302 Found in 0ms
...
`,
}
func init() {
cmdLog.Flag.StringVarP(&duration, "duration", "d", "", "duration to start streaming logs from")
}
type PostLogForm struct {
Duration int64 `json:"duration"`
}
func runLog(cmd *Command, args []string) {
if len(args) != 0 {
cmd.PrintUsage()
os.Exit(2)
}
var d int64
if duration != "" {
parsed, err := time.ParseDuration(duration)
if err != nil {
fmt.Println(err)
cmd.PrintUsage()
os.Exit(1)
}
d = parsed.Nanoseconds()
}
appName := mustApp()
endpoint := fmt.Sprintf("/apps/%s/log-sessions", appName)
form := &PostLogForm{Duration: d}
must(client.Post(os.Stdout, endpoint, form))
}