hopefully fixed formats for 'extras' and 'time diff'
This commit is contained in:
parent
1f1ec29f7c
commit
a8ccd953bb
1 changed files with 10 additions and 8 deletions
18
print.go
18
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)
|
||||
|
|
Loading…
Reference in a new issue