Logger: avoid panic when time is a string (not fmt.Stringer) (#44497)

This commit is contained in:
Ryan McKinley 2022-01-26 13:17:42 -08:00 committed by GitHub
parent 8a7b469679
commit 3c334cd8ba
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -91,12 +91,24 @@ func getRecord(keyvals ...interface{}) *record {
k, v := keyvals[i], keyvals[i+1]
if k == "t" {
t := v.(fmt.Stringer)
time, err := time.Parse("2006-01-02T15:04:05.999999999-0700", t.String())
if err == nil {
r.time = time
t, ok := v.(fmt.Stringer)
if ok {
time, err := time.Parse("2006-01-02T15:04:05.999999999-0700", t.String())
if err == nil {
r.time = time
continue
}
}
t3, ok := v.(string)
if ok {
// from alerting: 2022-01-26T12:03:41.655107858-08:00
time, err := time.Parse("2006-01-02T15:04:05.999999999-07:00", t3)
if err == nil {
r.time = time
continue
}
}
continue
}
if keyvals[i] == "msg" {