Skip to content

Commit

Permalink
Add timestamp to client log entries
Browse files Browse the repository at this point in the history
  • Loading branch information
portante authored and chmouel committed Apr 25, 2023
1 parent 77c54af commit fa6e389
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions gosmee/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,18 +127,22 @@ func (c goSmee) parse(data []byte) (payloadMsg, error) {
pm.contentType = pv
}
case "timestamp":
var ts string
var dt time.Time
if pv, ok := payloadValue.(float64); ok {
var ts string
ts = fmt.Sprintf("%.f", pv)
ts = ts[:len(ts)-3]

tsInt, err := strconv.ParseInt(ts, 10, 64)
if err != nil {
return payloadMsg{}, fmt.Errorf("cannot convert timestamp to int64")
}
dt = time.Unix(tsInt, 0)
} else {
dt = time.Now()
}
tsInt, err := strconv.ParseInt(ts, 10, 64)
if err != nil {
return payloadMsg{}, fmt.Errorf("cannot convert timestamp to int64")
}
dt := time.Unix(tsInt, 0)

pm.timestamp = dt.Format("20060102T15h04")
pm.timestamp = dt.Format("2006-01-02T15.04.01.000")
}
}

Expand Down Expand Up @@ -254,7 +258,7 @@ func (c goSmee) replayData(pm payloadMsg) error {
msg = fmt.Sprintf("%s %s", pm.eventID, msg)
}

msg = fmt.Sprintf("%s replayed to %s, status: %s", msg, ansi.Color(c.targetURL, "green+ub"), ansi.Color(fmt.Sprintf("%d", resp.StatusCode), "blue+b"))
msg = fmt.Sprintf("%s %s replayed to %s, status: %s", pm.timestamp, msg, ansi.Color(c.targetURL, "green+ub"), ansi.Color(fmt.Sprintf("%d", resp.StatusCode), "blue+b"))
if resp.StatusCode > 299 {
msg = fmt.Sprintf("%s, error: %s", msg, resp.Status)
}
Expand Down

0 comments on commit fa6e389

Please sign in to comment.