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,13 +91,25 @@ func getRecord(keyvals ...interface{}) *record {
k, v := keyvals[i], keyvals[i+1] k, v := keyvals[i], keyvals[i+1]
if k == "t" { if k == "t" {
t := v.(fmt.Stringer) t, ok := v.(fmt.Stringer)
if ok {
time, err := time.Parse("2006-01-02T15:04:05.999999999-0700", t.String()) time, err := time.Parse("2006-01-02T15:04:05.999999999-0700", t.String())
if err == nil { if err == nil {
r.time = time r.time = time
}
continue 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
}
}
}
if keyvals[i] == "msg" { if keyvals[i] == "msg" {
r.msg = v.(string) r.msg = v.(string)