Skip to content

Commit 916e3fa

Browse files
committed
feat: update logs API
1 parent c6c60c9 commit 916e3fa

2 files changed

Lines changed: 36 additions & 36 deletions

File tree

internal/app/enaptercli/cmd_device_logs.go

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@ import (
1515

1616
type cmdDeviceLogs struct {
1717
cmdDevice
18-
deviceID string
19-
follow bool
20-
from cli.Timestamp
21-
to cli.Timestamp
22-
offset int
23-
limit int
24-
severity string
25-
order string
26-
showFilter string
18+
deviceID string
19+
follow bool
20+
receivedAtGte cli.Timestamp
21+
receivedAtLt cli.Timestamp
22+
offset int
23+
limit int
24+
severity string
25+
order string
26+
retention string
2727
}
2828

2929
func buildCmdDeviceLogs() *cli.Command {
@@ -54,14 +54,14 @@ func (c *cmdDeviceLogs) Flags() []cli.Flag {
5454
Usage: "Follow the log output",
5555
Destination: &c.follow,
5656
}, &cli.TimestampFlag{
57-
Name: "from",
57+
Name: "received-at-gte",
5858
Usage: "From timestamp in RFC 3339 format (e.g. 2006-01-02T15:04:05Z)",
59-
Destination: &c.from,
59+
Destination: &c.receivedAtGte,
6060
Layout: time.RFC3339,
6161
}, &cli.TimestampFlag{
62-
Name: "to",
62+
Name: "received-at-lt",
6363
Usage: "To timestamp in RFC 3339 format (e.g. 2006-01-02T15:04:05Z)",
64-
Destination: &c.to,
64+
Destination: &c.receivedAtLt,
6565
Layout: time.RFC3339,
6666
}, &cli.IntFlag{
6767
Name: "limit",
@@ -89,12 +89,12 @@ func (c *cmdDeviceLogs) Flags() []cli.Flag {
8989
return nil
9090
},
9191
}, &cli.StringFlag{
92-
Name: "show",
93-
Usage: "Filter logs by criteria (ALL[default], PERSISTED_ONLY, TEMPORARY_ONLY)",
94-
Destination: &c.showFilter,
92+
Name: "retention",
93+
Usage: "Filter logs by retention (ALL[default], PERSISTENT, EPHEMERAL)",
94+
Destination: &c.retention,
9595
Action: func(_ *cli.Context, v string) error {
96-
if v != "ALL" && v != "PERSISTED_ONLY" && v != "TEMPORARY_ONLY" {
97-
return fmt.Errorf("%w: should be one of [ALL, PERSISTED_ONLY, TEMPORARY_ONLY]", errUnsupportedFlagValue)
96+
if v != "ALL" && v != "PERSISTENT" && v != "EPHEMERAL" {
97+
return fmt.Errorf("%w: should be one of [ALL, PERSISTENT, EPHEMERAL]", errUnsupportedFlagValue)
9898
}
9999
return nil
100100
},
@@ -109,28 +109,28 @@ func (c *cmdDeviceLogs) do(ctx context.Context) error {
109109
}
110110

111111
func (c *cmdDeviceLogs) doFollow(ctx context.Context) error {
112-
if c.from.Value() != nil {
113-
return cli.Exit("Option received_at_from is unsupported in follow mode.", 1)
112+
if c.receivedAtGte.Value() != nil {
113+
return cli.Exit("Option --received-at-gte is unsupported in follow mode.", 1)
114114
}
115-
if c.to.Value() != nil {
116-
return cli.Exit("Option received_at_to is unsupported in follow mode.", 1)
115+
if c.receivedAtLt.Value() != nil {
116+
return cli.Exit("Option --received-at-lt is unsupported in follow mode.", 1)
117117
}
118118
if c.offset > 0 {
119-
return cli.Exit("Option offset is unsupported in follow mode.", 1)
119+
return cli.Exit("Option --offset is unsupported in follow mode.", 1)
120120
}
121121
if c.limit > 0 {
122-
return cli.Exit("Option limit is unsupported in follow mode.", 1)
122+
return cli.Exit("Option --limit is unsupported in follow mode.", 1)
123123
}
124124
if c.order != "" {
125-
return cli.Exit("Option order is unsupported in follow mode.", 1)
125+
return cli.Exit("Option --order is unsupported in follow mode.", 1)
126126
}
127127

128128
query := url.Values{}
129129
if c.severity != "" {
130130
query.Add("severity", c.severity)
131131
}
132-
if c.showFilter != "" {
133-
query.Add("show", c.showFilter)
132+
if c.retention != "" {
133+
query.Add("retention", c.retention)
134134
}
135135

136136
return c.runWebSocket(ctx, runWebSocketParams{
@@ -164,11 +164,11 @@ func (c *cmdDeviceLogs) doFollow(ctx context.Context) error {
164164

165165
func (c *cmdDeviceLogs) doList(ctx context.Context) error {
166166
query := url.Values{}
167-
if c.from.Value() != nil {
168-
query.Add("received_at_from", c.from.Value().Format(time.RFC3339))
167+
if c.receivedAtGte.Value() != nil {
168+
query.Add("received_at.gte", c.receivedAtGte.Value().Format(time.RFC3339))
169169
}
170-
if c.to.Value() != nil {
171-
query.Add("received_at_to", c.to.Value().Format(time.RFC3339))
170+
if c.receivedAtLt.Value() != nil {
171+
query.Add("received_at.lt", c.receivedAtLt.Value().Format(time.RFC3339))
172172
}
173173
if c.offset > 0 {
174174
query.Add("offset", strconv.Itoa(c.offset))
@@ -182,8 +182,8 @@ func (c *cmdDeviceLogs) doList(ctx context.Context) error {
182182
if c.order != "" {
183183
query.Add("order", c.order)
184184
}
185-
if c.showFilter != "" {
186-
query.Add("show", c.showFilter)
185+
if c.retention != "" {
186+
query.Add("retention", c.retention)
187187
}
188188

189189
return c.doHTTPRequest(ctx, doHTTPRequestParams{

internal/app/enaptercli/testdata/helps/enapter device logs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ OPTIONS:
1111
--site-id value Site ID
1212
--device-id value, -d value Device ID
1313
--follow, -f Follow the log output (default: false)
14-
--from value From timestamp in RFC 3339 format (e.g. 2006-01-02T15:04:05Z)
15-
--to value To timestamp in RFC 3339 format (e.g. 2006-01-02T15:04:05Z)
14+
--received-at-gte value From timestamp in RFC 3339 format (e.g. 2006-01-02T15:04:05Z)
15+
--received-at-lt value To timestamp in RFC 3339 format (e.g. 2006-01-02T15:04:05Z)
1616
--limit value, -l value Maximum number of logs to retrieve (default: 0)
1717
--offset value, -o value Number of logs to skip when retrieving (default: 0)
1818
--severity value, -s value Filter logs by severity
1919
--order value Order logs by criteria (RECEIVED_AT_ASC[default], RECEIVED_AT_DESC)
20-
--show value Filter logs by criteria (ALL[default], PERSISTED_ONLY, TEMPORARY_ONLY)
20+
--retention value Filter logs by retention (ALL[default], PERSISTENT, EPHEMERAL)
2121
--help, -h show help
2222

2323
ENVIRONMENT VARIABLES:

0 commit comments

Comments
 (0)