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_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)