Skip to content

Commit 3cfd4a0

Browse files
committed
Migrate logs command parameters to match journalctl
Moves some of the flags for the logs commands to align more closely with the journalctl syntax and fixes some typos in the original. Signed-off-by: Alex Ellis (OpenFaaS Ltd) <[email protected]>
1 parent d2a4ff6 commit 3cfd4a0

File tree

2 files changed

+18
-18
lines changed

2 files changed

+18
-18
lines changed

commands/logs.go

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ type logFlags struct {
2828
instance string
2929
since time.Duration
3030
sinceTime flags.TimestampFlag
31-
follow bool
32-
tail int
31+
tail bool
32+
lines int
3333
token string
3434
logFormat flags.LogFormat
3535
includeName bool
@@ -44,15 +44,15 @@ func init() {
4444
}
4545

4646
var functionLogsCmd = &cobra.Command{
47-
Use: `logs <NAME> [--tls-no-verify] [--gateway]`,
48-
Aliases: []string{"ls"},
49-
Short: "Tail logs from your functions",
50-
Long: "Tail logs from your functions",
51-
Example: `faas-cli logs echo
52-
faas-cli logs echo --tail=5
53-
faas-cli logs echo --follow=false
54-
faas-cli logs echo --follow=false --since=10m
55-
faas-cli logs echo --follow=false --since=2010-01-01T00:00:00Z`,
47+
Use: `logs <NAME> [--tls-no-verify] [--gateway] [--output=text/json]`,
48+
Short: "Fetch logs for a functions",
49+
Long: "Fetch logs for a given function name in plain text or JSON format.",
50+
Example: ` faas-cli logs FN
51+
faas-cli logs FN --output=json
52+
faas-cli logs FN --lines=5
53+
faas-cli logs FN --tail=false --since=10m
54+
faas-cli logs FN --tail=false --since=2010-01-01T00:00:00Z
55+
`,
5656
Args: cobra.MaximumNArgs(1),
5757
RunE: runLogs,
5858
PreRunE: noopPreRunCmd,
@@ -77,12 +77,12 @@ func initLogCmdFlags(cmd *cobra.Command) {
7777

7878
cmd.Flags().DurationVar(&logFlagValues.since, "since", 0*time.Second, "return logs newer than a relative duration like 5s")
7979
cmd.Flags().Var(&logFlagValues.sinceTime, "since-time", "include logs since the given timestamp (RFC3339)")
80-
cmd.Flags().IntVar(&logFlagValues.tail, "tail", -1, "number of recent log lines file to display. Defaults to -1, unlimited if <=0")
81-
cmd.Flags().BoolVar(&logFlagValues.follow, "follow", true, "continue printing new logs until the end of the request, up to 30s")
80+
cmd.Flags().IntVar(&logFlagValues.lines, "lines", -1, "number of recent log lines file to display. Defaults to -1, unlimited if <=0")
81+
cmd.Flags().BoolVarP(&logFlagValues.tail, "tail", "t", true, "tail logs and continue printing new logs until the end of the request, up to 30s")
8282
cmd.Flags().StringVarP(&logFlagValues.token, "token", "k", "", "Pass a JWT token to use instead of basic auth")
8383

8484
logFlagValues.timeFormat = flags.TimeFormat(time.RFC3339)
85-
cmd.Flags().Var(&logFlagValues.logFormat, "format", "output format. Note that JSON format will always include all log message keys (plain|key-value|json)")
85+
cmd.Flags().VarP(&logFlagValues.logFormat, "output", "o", "output logs as (plain|keyvalue|json), JSON includes all available keys")
8686
cmd.Flags().Var(&logFlagValues.timeFormat, "time-format", "string format for the timestamp, any value go time format string is allowed, empty will not print the timestamp")
8787
cmd.Flags().BoolVar(&logFlagValues.includeName, "name", false, "print the function name")
8888
cmd.Flags().BoolVar(&logFlagValues.includeInstance, "instance", false, "print the function instance name/id")
@@ -129,9 +129,9 @@ func logRequestFromFlags(cmd *cobra.Command, args []string) logs.Request {
129129
return logs.Request{
130130
Name: args[0],
131131
Namespace: ns,
132-
Tail: logFlagValues.tail,
132+
Tail: logFlagValues.lines,
133133
Since: sinceValue(logFlagValues.sinceTime.AsTime(), logFlagValues.since),
134-
Follow: logFlagValues.follow,
134+
Follow: logFlagValues.tail,
135135
}
136136
}
137137

commands/logs_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ func Test_logsCmdFlagParsing(t *testing.T) {
2222
expected logs.Request
2323
}{
2424
{"name only passed, follow on by default", []string{"funcFoo"}, logs.Request{Name: "funcFoo", Follow: true, Tail: -1}},
25-
{"can disable follow", []string{"funcFoo", "--follow=false"}, logs.Request{Name: "funcFoo", Follow: false, Tail: -1}},
26-
{"can limit number of messages returned", []string{"funcFoo", "--tail=5"}, logs.Request{Name: "funcFoo", Follow: true, Tail: 5}},
25+
{"can disable follow", []string{"funcFoo", "--tail=false"}, logs.Request{Name: "funcFoo", Follow: false, Tail: -1}},
26+
{"can limit number of messages returned", []string{"funcFoo", "--lines=5"}, logs.Request{Name: "funcFoo", Follow: true, Tail: 5}},
2727
{"can set timestamp to send logs since using duration", []string{"funcFoo", "--since=5m"}, logs.Request{Name: "funcFoo", Follow: true, Tail: -1, Since: &fiveMinAgo}},
2828
{"can set timestamp to send logs since using timestamp", []string{"funcFoo", "--since-time=" + fiveMinAgoStr}, logs.Request{Name: "funcFoo", Follow: true, Tail: -1, Since: &fiveMinAgo}},
2929
}

0 commit comments

Comments
 (0)