hopefully fixed formats for 'extras' and 'time diff'

This commit is contained in:
Daniel Sommer 2023-11-02 12:21:50 +01:00
parent 1f1ec29f7c
commit a8ccd953bb

View file

@ -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_TIMESTAMP, now.Format(GetDateFormat()))
formatted = strings.ReplaceAll(formatted, PLACEHOLDER_LOGLEVEL, logLevel.name) formatted = strings.ReplaceAll(formatted, PLACEHOLDER_LOGLEVEL, logLevel.name)
formatted = strings.ReplaceAll(formatted, PLACEHOLDER_MESSAGE, message) formatted = strings.ReplaceAll(formatted, PLACEHOLDER_MESSAGE, message)
tmp := "" if len(extras) == 0 {
if len(extras) > 0 { formatted = strings.ReplaceAll(formatted, GetExtrasFormat(), "")
tmp = strings.Join(extras, GetExtrasSeparator()) } else {
format := GetExtrasFormat()
formatted = strings.ReplaceAll(formatted, format, strings.ReplaceAll(format, PLACEHOLDER_EXTRAS, strings.Join(extras, GetExtrasSeparator())))
} }
formatted = strings.ReplaceAll(formatted, GetExtrasFormat(), tmp) if timestamp <= 0 {
tmp = "" formatted = strings.ReplaceAll(formatted, GetTimediffFormat(), "")
if timestamp >= 0 { } else {
tmp = strconv.FormatInt(now.UnixMilli()-timestamp, 10) + "ms" 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)) fmt.Println(strings.TrimSpace(formatted))
if logLevel.level == FatalLevel.level { if logLevel.level == FatalLevel.level {
os.Exit(1) os.Exit(1)