From 60eb2145ec5e4369cd26e83f52ed2f80821de35c Mon Sep 17 00:00:00 2001 From: Samantha Date: Fri, 10 Feb 2023 12:01:28 -0500 Subject: [PATCH] logger: Include msg in object serialization error (#6650) Include the `msg` for additional context when JSON serialization of the log object fails. --- log/log.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/log/log.go b/log/log.go index 08f75cf2c..023684376 100644 --- a/log/log.go +++ b/log/log.go @@ -320,7 +320,7 @@ func (log *impl) Infof(format string, a ...interface{}) { func (log *impl) InfoObject(msg string, obj interface{}) { jsonObj, err := json.Marshal(obj) if err != nil { - log.auditAtLevel(syslog.LOG_ERR, fmt.Sprintf("Object could not be serialized to JSON. Raw: %+v", obj)) + log.auditAtLevel(syslog.LOG_ERR, fmt.Sprintf("Object for msg %q could not be serialized to JSON. Raw: %+v", msg, obj)) return } @@ -354,7 +354,7 @@ func (log *impl) AuditInfof(format string, a ...interface{}) { func (log *impl) AuditObject(msg string, obj interface{}) { jsonObj, err := json.Marshal(obj) if err != nil { - log.auditAtLevel(syslog.LOG_ERR, fmt.Sprintf("Object could not be serialized to JSON. Raw: %+v", obj)) + log.auditAtLevel(syslog.LOG_ERR, fmt.Sprintf("Object for msg %q could not be serialized to JSON. Raw: %+v", msg, obj)) return }