Skip to content

Commit

Permalink
DXCDT-403: Separate rendering for logs tail and logs list (#672)
Browse files Browse the repository at this point in the history
Separating view for log tail and log list

Co-authored-by: Will Vedder <will.vedder@okta.com>
Co-authored-by: Rita Zerrizuela <zeta@widcket.com>
  • Loading branch information
3 people authored Mar 30, 2023
1 parent 55d6917 commit e801635
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 18 deletions.
5 changes: 2 additions & 3 deletions internal/cli/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,7 @@ func listLogsCmd(cli *cli) *cobra.Command {
return fmt.Errorf("An unexpected error occurred while getting logs: %v", err)
}

var logsCh chan []*management.Log
cli.renderer.LogList(list, logsCh, !cli.debug)
cli.renderer.LogList(list, !cli.debug)
return nil
},
}
Expand Down Expand Up @@ -154,7 +153,7 @@ func tailLogsCmd(cli *cli) *cobra.Command {
}
}()

cli.renderer.LogList(list, logsCh, !cli.debug)
cli.renderer.LogTail(list, logsCh, !cli.debug)
return nil
},
}
Expand Down
35 changes: 20 additions & 15 deletions internal/display/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ func (v *logView) typeDesc() (typ, desc string) {
return typ, desc
}

func (r *Renderer) LogList(logs []*management.Log, ch <-chan []*management.Log, silent bool) {
func (r *Renderer) LogList(logs []*management.Log, silent bool) {
resource := "logs"

r.Heading(resource)
Expand All @@ -158,23 +158,28 @@ func (r *Renderer) LogList(logs []*management.Log, ch <-chan []*management.Log,
res = append(res, &logView{Log: l, silent: silent, raw: l})
}

var viewChan chan View
r.Results(res)
}

func (r *Renderer) LogTail(logs []*management.Log, ch <-chan []*management.Log, silent bool) {
r.Heading("logs")

var res []View
for _, l := range logs {
res = append(res, &logView{Log: l, silent: silent, raw: l})
}

if ch != nil {
viewChan = make(chan View)
viewChan := make(chan View)

go func() {
defer close(viewChan)
go func() {
defer close(viewChan)

for list := range ch {
for _, l := range list {
viewChan <- &logView{Log: l, silent: silent, raw: l}
}
for list := range ch {
for _, l := range list {
viewChan <- &logView{Log: l, silent: silent, raw: l}
}
}()

r.Stream(res, viewChan) // streams results for `auth0 logs tail`
}
}
}()

r.Results(res) // Includes headers for `auth0 logs list`
r.Stream(res, viewChan)
}

0 comments on commit e801635

Please sign in to comment.