Skip to content

Commit

Permalink
Update logs display
Browse files Browse the repository at this point in the history
Co-authored-by: Patrick Carey <[email protected]>
  • Loading branch information
shushen and Patrick Carey committed Jan 22, 2021
1 parent 8c6cd46 commit e7a6d9e
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 10 deletions.
3 changes: 1 addition & 2 deletions internal/cli/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ package cli

import (
"github.com/spf13/cobra"
"time"

"gopkg.in/auth0.v5/management"
"time"
)

func logsCmd(cli *cli) *cobra.Command {
Expand Down
55 changes: 47 additions & 8 deletions internal/display/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,58 @@ package display

import (
"fmt"
"strings"
"time"

"github.com/auth0/auth0-cli/internal/ansi"
"github.com/logrusorgru/aurora"
"gopkg.in/auth0.v5/management"
)

func (r *Renderer) LogList(logs []*management.Log) {
for _, c := range logs {
// TODO: Info/Warn/Error based on type
r.Infof(fmt.Sprintf("%s\t%s\t%s",
ansi.Faint(c.GetDate().Format(time.RFC3339)),
ansi.Faint(c.TypeName()),
ansi.Faint(*c.ClientName),
))
for _, l := range logs {
// colorize the event type field based on whether it's a success or failure
var logType aurora.Value
if t := l.GetType(); strings.HasPrefix(t, "s") {
logType = aurora.Green(t)
} else if strings.HasPrefix(t, "f") {
logType = aurora.BrightRed(t)
} else {
logType = aurora.Reset(t)
}

fmt.Fprintf(
r.Writer,
"[%s] (%s) client_name=%q client_id=%q",
l.Date.Format(time.RFC3339),
logType,
l.GetClientName(),
l.GetClientID(),
)

// if userAgent is present in the log, then add it to the output
reqMap, _ := l.Details["request"].(map[string]interface{})
userAgent, _ := reqMap["userAgent"].(string)
if userAgent != "" {
fmt.Fprintf(
r.Writer,
" user_agent=%q",
userAgent,
)
}

// if an error is present in the log, add it to the output
errMap, _ := l.Details["error"].(map[string]interface{})
errMsg, _ := errMap["message"].(string)
errType, _ := errMap["type"].(string)
if errType != "" || errMsg != "" {
fmt.Fprintf(
r.Writer,
" error_type=%q error_message=%q",
errType,
errMsg,
)
}

fmt.Fprint(r.Writer, "\n")
}
}

0 comments on commit e7a6d9e

Please sign in to comment.