Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

filter flag handled +info usage #124

Merged
merged 2 commits into from
Aug 19, 2015
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions api/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func LogsURL(app string) (*http.Response, error) {
return req.Do()
}

func Logs(logsURL string, n int) (*http.Response, error) {
func Logs(logsURL string, n int, filter string) (*http.Response, error) {
u, err := url.Parse(logsURL)
if err != nil {
return nil, errgo.Mask(err)
Expand All @@ -25,8 +25,9 @@ func Logs(logsURL string, n int) (*http.Response, error) {
URL: u.Scheme + "://" + u.Host,
Endpoint: u.Path,
Params: map[string]interface{}{
"token": u.Query().Get("token"),
"n": n,
"token": u.Query().Get("token"),
"n": n,
"filter": filter,
},
}
return req.Do()
Expand Down
19 changes: 12 additions & 7 deletions apps/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ type LogsRes struct {
App *api.App `json:"app"`
}

func Logs(appName string, stream bool, n int) error {
func Logs(appName string, stream bool, n int, filter string) error {
res, err := api.LogsURL(appName)
if err != nil {
return errgo.Mask(err, errgo.Any)
Expand All @@ -52,20 +52,20 @@ func Logs(appName string, stream bool, n int) error {
return errgo.Mask(err, errgo.Any)
}

if err = dumpLogs(logsRes.LogsURL, n); err != nil {
if err = dumpLogs(logsRes.LogsURL, n, filter); err != nil {
return errgo.Mask(err, errgo.Any)
}

if stream {
if err = streamLogs(logsRes.LogsURL); err != nil {
if err = streamLogs(logsRes.LogsURL, filter); err != nil {
return errgo.Mask(err, errgo.Any)
}
}
return nil
}

func dumpLogs(logsURL string, n int) error {
res, err := api.Logs(logsURL, n)
func dumpLogs(logsURL string, n int, filter string) error {
res, err := api.Logs(logsURL, n, filter)
if err != nil {
return errgo.Mask(err, errgo.Any)
}
Expand All @@ -84,7 +84,7 @@ func dumpLogs(logsURL string, n int) error {
return nil
}

func streamLogs(logsRawURL string) error {
func streamLogs(logsRawURL string, filter string) error {
var (
err error
buffer [2048]byte
Expand All @@ -101,7 +101,12 @@ func streamLogs(logsRawURL string) error {
logsURL.Scheme = "ws"
}

conn, err := websocket.Dial(logsURL.String()+"&stream=true", "", "http://scalingo-cli.local/"+config.Version)
logsURLString := fmt.Sprintf("%s&stream=true", logsURL.String())
if filter != "" {
logsURLString = fmt.Sprintf("%s&filter=%s", logsURLString, filter)
}

conn, err := websocket.Dial(logsURLString, "", "http://scalingo-cli.local/"+config.Version)
if err != nil {
return errgo.Mask(err, errgo.Any)
}
Expand Down
10 changes: 6 additions & 4 deletions cmd/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,18 @@ var (
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'`,
Get 100 lines: 'scalingo --app my-app logs -n 100'
Real-Time logs: 'scalingo --app my-app logs -f'
Get lines with filter: 'scalingo --app my-app logs -n 100 -F web-1|worker-2'`,
Flags: []cli.Flag{appFlag,
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 process that will be displayed", EnvVar: ""},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Filter process that will be displayed" -> "Filter container logs that will be displayed"

},
Action: func(c *cli.Context) {
currentApp := appdetect.CurrentApp(c)
if len(c.Args()) == 0 || len(c.Args()) == 2 && c.Int("n") != 0 {
if err := apps.Logs(currentApp, c.Bool("f"), c.Int("n")); err != nil {
if len(c.Args()) == 0 {
if err := apps.Logs(currentApp, c.Bool("f"), c.Int("n"), c.String("F")); err != nil {
errorQuit(err)
}
} else {
Expand Down