trim log message if 'extras' or 'time diff' is empty

This commit is contained in:
Daniel Sommer 2023-11-02 15:20:09 +01:00
parent 0b5381f82e
commit cb89138842

View file

@ -69,12 +69,14 @@ func print(logLevel logLevel, message string, timestamp int64, extras ...string)
formatted = strings.ReplaceAll(formatted, PLACEHOLDER_MESSAGE, message)
if len(extras) == 0 {
formatted = strings.ReplaceAll(formatted, GetExtrasFormat(), "")
formatted = strings.TrimSpace(formatted)
} else {
format := GetExtrasFormat()
formatted = strings.ReplaceAll(formatted, format, strings.ReplaceAll(format, PLACEHOLDER_EXTRAS, strings.Join(extras, GetExtrasSeparator())))
}
if timestamp <= 0 {
formatted = strings.ReplaceAll(formatted, GetTimediffFormat(), "")
formatted = strings.TrimSpace(formatted)
} else {
format := GetTimediffFormat()
formatted = strings.ReplaceAll(formatted, format, strings.ReplaceAll(format, PLACEHOLDER_TIMEDIFF, strconv.FormatInt(now.UnixMilli()-timestamp, 10)+"ms"))