logger: Include msg in object serialization error (#6650)

Include the `msg` for additional context when JSON serialization of the
log object fails.
This commit is contained in:
Samantha 2023-02-10 12:01:28 -05:00 committed by GitHub
parent 595a9511ed
commit 60eb2145ec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 2 additions and 2 deletions

View File

@ -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
}