fix(logging): Clean up extra empty spaces when redirectLogger is used (#16255)

This commit is contained in:
Mingyang Zheng 2024-12-05 06:30:10 -08:00 committed by GitHub
parent 0ea4c1422e
commit 0c74b68f55
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 7 additions and 2 deletions

View File

@ -119,10 +119,15 @@ func (l *redirectLogger) Print(level telegraf.LogLevel, ts time.Time, prefix str
for k, v := range attr {
parts = append(parts, fmt.Sprintf("%s=%v", k, v))
}
attrMsg = " (" + strings.Join(parts, ",") + ")"
attrMsg = "(" + strings.Join(parts, ",") + ")"
}
msg := append([]interface{}{ts.In(time.UTC).Format(time.RFC3339), " ", level.Indicator(), " ", prefix + attrMsg}, args...)
msg := []interface{}{ts.In(time.UTC).Format(time.RFC3339), level.Indicator(), prefix + attrMsg}
if prefix+attrMsg != "" {
msg = append(msg, prefix+attrMsg)
}
msg = append(msg, args...)
fmt.Fprintln(l.writer, msg...)
}