When logging structs, do log fields of type time.Time (timestamps)

The simplistic logging approach we've followed so far is to not log struct
fields that are themselves structs, which time.Time is. So we skipped, but do
log it now.
This commit is contained in:
Mechiel Lukkien 2025-03-19 21:52:31 +01:00
parent 719dc2bee1
commit 5294a63c26
No known key found for this signature in database

View File

@ -393,6 +393,8 @@ func formatString(s string) string {
return s
}
var typeTime = reflect.TypeFor[time.Time]()
func stringValue(iscid, nested bool, v any) string {
// Handle some common types first.
if v == nil {
@ -478,7 +480,8 @@ func stringValue(iscid, nested bool, v any) string {
if !t.Field(i).IsExported() {
continue
}
if j == 0 && (fv.Kind() == reflect.Struct || fv.Kind() == reflect.Ptr || fv.Kind() == reflect.Interface) {
// todo: decide on better approach about which fields to include while preventing recursion
if j == 0 && (fv.Kind() == reflect.Struct || fv.Kind() == reflect.Ptr || fv.Kind() == reflect.Interface) && fv.Type() != typeTime {
// Don't recurse.
continue
}