/
logs.go
62 lines (58 loc) · 1.83 KB
/
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
61
62
package cmd
import (
"github.com/Scalingo/cli/appdetect"
"github.com/Scalingo/cli/apps"
"github.com/Scalingo/cli/cmd/autocomplete"
"github.com/Scalingo/cli/db"
"github.com/urfave/cli"
)
var (
LogsCommand = cli.Command{
Name: "logs",
ShortName: "l",
Category: "App Management",
Usage: "Get the logs of your applications",
Description: `Get the logs of your applications
Example:
Get 100 lines: 'scalingo --app my-app logs -n 100'
Real-Time logs: 'scalingo --app my-app logs -f'
Addon logs: 'scalingo --app my-app --addon addon_uuid logs'
Get lines with filter:
'scalingo --app my-app logs -F web'
'scalingo --app my-app logs -F web-1'
'scalingo --app my-app logs --follow -F "worker|clock"'`,
Flags: []cli.Flag{appFlag, addonFlag,
cli.IntFlag{Name: "lines, n", Value: 20, Usage: "Number of log lines to dump", EnvVar: ""},
cli.BoolFlag{Name: "follow, f", Usage: "Stream logs of app, (as \"tail -f\")", EnvVar: ""},
cli.StringFlag{Name: "filter, F", Usage: "Filter containers logs that will be displayed", EnvVar: ""},
},
Action: func(c *cli.Context) {
currentApp := appdetect.CurrentApp(c)
if len(c.Args()) != 0 {
cli.ShowCommandHelp(c, "logs")
return
}
var addonName string
if c.GlobalString("addon") != "<addon_id>" {
addonName = c.GlobalString("addon")
} else if c.String("addon") != "<addon_id>" {
addonName = c.String("addon")
}
var err error
if addonName == "" {
err = apps.Logs(currentApp, c.Bool("f"), c.Int("n"), c.String("F"))
} else {
err = db.Logs(currentApp, addonName, db.LogsOpts{
Follow: c.Bool("f"),
Count: c.Int("n"),
})
}
if err != nil {
errorQuit(err)
}
},
BashComplete: func(c *cli.Context) {
autocomplete.CmdFlagsAutoComplete(c, "logs")
},
}
)