From a8ccd953bb98481ab63d807b2584944824a8a987 Mon Sep 17 00:00:00 2001 From: velvettear Date: Thu, 2 Nov 2023 12:21:50 +0100 Subject: [PATCH] hopefully fixed formats for 'extras' and 'time diff' --- print.go | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/print.go b/print.go index 9a29340..3f3acdf 100644 --- a/print.go +++ b/print.go @@ -68,16 +68,18 @@ func print(logLevel logLevel, message string, timestamp int64, extras ...string) formatted = strings.ReplaceAll(formatted, PLACEHOLDER_TIMESTAMP, now.Format(GetDateFormat())) formatted = strings.ReplaceAll(formatted, PLACEHOLDER_LOGLEVEL, logLevel.name) formatted = strings.ReplaceAll(formatted, PLACEHOLDER_MESSAGE, message) - tmp := "" - if len(extras) > 0 { - tmp = strings.Join(extras, GetExtrasSeparator()) + if len(extras) == 0 { + formatted = strings.ReplaceAll(formatted, GetExtrasFormat(), "") + } else { + format := GetExtrasFormat() + formatted = strings.ReplaceAll(formatted, format, strings.ReplaceAll(format, PLACEHOLDER_EXTRAS, strings.Join(extras, GetExtrasSeparator()))) } - formatted = strings.ReplaceAll(formatted, GetExtrasFormat(), tmp) - tmp = "" - if timestamp >= 0 { - tmp = strconv.FormatInt(now.UnixMilli()-timestamp, 10) + "ms" + if timestamp <= 0 { + formatted = strings.ReplaceAll(formatted, GetTimediffFormat(), "") + } else { + format := GetExtrasFormat() + formatted = strings.ReplaceAll(formatted, format, strings.ReplaceAll(format, PLACEHOLDER_EXTRAS, strconv.FormatInt(now.UnixMilli()-timestamp, 10)+"ms")) } - formatted = strings.ReplaceAll(formatted, GetTimediffFormat(), tmp) fmt.Println(strings.TrimSpace(formatted)) if logLevel.level == FatalLevel.level { os.Exit(1)