diff --git a/internal/cli/logs.go b/internal/cli/logs.go index 88ae776e5..3ce59751c 100644 --- a/internal/cli/logs.go +++ b/internal/cli/logs.go @@ -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 }, } @@ -154,7 +153,7 @@ func tailLogsCmd(cli *cli) *cobra.Command { } }() - cli.renderer.LogList(list, logsCh, !cli.debug) + cli.renderer.LogsTail(list, logsCh, !cli.debug) return nil }, } diff --git a/internal/display/logs.go b/internal/display/logs.go index 3de96889b..0f52d4c4b 100644 --- a/internal/display/logs.go +++ b/internal/display/logs.go @@ -144,7 +144,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) LogsTail(logs []*management.Log, ch <-chan []*management.Log, silent bool) { resource := "logs" r.Heading(resource) @@ -160,22 +160,35 @@ 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 + var viewChan = make(chan View) - if ch != nil { - 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.Stream(res, viewChan) +} + +func (r *Renderer) LogList(logs []*management.Log, silent bool) { + resource := "logs" + + r.Heading(resource) + + if len(logs) == 0 { + r.EmptyState(resource) + r.Infof("To generate logs, run a test command like 'auth0 test login' or 'auth0 test token'") + return + } + + var res []View + for _, l := range logs { + res = append(res, &logView{Log: l, silent: silent, raw: l}) } r.Results(res) //Includes headers for `auth0 logs list`