Skip to content

Commit

Permalink
Truncate log entry timestamp to milliseconds
Browse files Browse the repository at this point in the history
  • Loading branch information
rugwirobaker committed Oct 6, 2021
1 parent ebdc8ec commit 5481760
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions cmd/presenters/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"io"
"strings"
"time"

"github.com/logrusorgru/aurora"
"github.com/superfly/flyctl/pkg/logs"
Expand All @@ -30,10 +31,14 @@ func (lp *LogPresenter) printEntry(w io.Writer, asJSON bool, entry logs.LogEntry
return
}

// Trim milliseconds from entry.Timestamp string
entry.Timestamp = strings.Split(entry.Timestamp, ".")[0]
// parse entry.Timestamp and truncate from nanoseconds to milliseconds
timestamp, err := time.Parse(time.RFC3339Nano, entry.Timestamp)
if err != nil {
fmt.Fprintf(w, "Error parsing timestamp: %s\n", err)
return
}

fmt.Fprintf(w, "%s ", aurora.Faint(entry.Timestamp))
fmt.Fprintf(w, "%s ", aurora.Faint(timestamp.Format("2006-01-02T15:04:05.000")))

if !lp.HideAllocID {
if entry.Meta.Event.Provider != "" {
Expand Down

0 comments on commit 5481760

Please sign in to comment.