From f05a5f8630af35fc3bfbd1cbd208d147f3804ccf Mon Sep 17 00:00:00 2001 From: Keepers Date: Thu, 12 Dec 2024 10:57:42 -0700 Subject: [PATCH] do not log empty labels and comments (#93) --- clog/builder.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/clog/builder.go b/clog/builder.go index ba4a1a7..6e10246 100644 --- a/clog/builder.go +++ b/clog/builder.go @@ -76,9 +76,14 @@ func (b builder) log(l logLevel, msg string) { cv["error_labels"] = cluerr.Labels(b.err) } - // finally, make sure we attach the labels and comments - cv["clog_labels"] = maps.Keys(b.labels) - cv["clog_comments"] = maps.Keys(b.comments) + // attach the labels and comments, if populated + if len(b.labels) > 0 { + cv["clog_labels"] = maps.Keys(b.labels) + } + + if len(b.comments) > 0 { + cv["clog_comments"] = maps.Keys(b.comments) + } if b.skipCallerJumps > 0 { zsl = zsl.WithOptions(zap.AddCallerSkip(b.skipCallerJumps))