From 5294a63c26b93c8aa07d86fbbd7af9ddc81c2099 Mon Sep 17 00:00:00 2001 From: Mechiel Lukkien Date: Wed, 19 Mar 2025 21:52:31 +0100 Subject: [PATCH] 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. --- mlog/log.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/mlog/log.go b/mlog/log.go index 327e674..dd6a21a 100644 --- a/mlog/log.go +++ b/mlog/log.go @@ -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 }