Fix log format

This commit is contained in:
世界 2022-07-22 14:28:29 +08:00
parent e531e89b4b
commit 7bc7b72c61
No known key found for this signature in database
GPG key ID: CD109927C34A63C4
2 changed files with 9 additions and 3 deletions

View file

@ -52,7 +52,7 @@ func (l *simpleLogger) Log(ctx context.Context, level Level, args []any) {
if level > l.level {
return
}
message := l.formatter.Format(ctx, level, l.tag, F.ToString(args...), time.Now()) + "\n"
message := l.formatter.Format(ctx, level, l.tag, F.ToString(args...), time.Now())
if level == LevelPanic {
panic(message)
}

View file

@ -75,7 +75,10 @@ func (f Formatter) Format(ctx context.Context, level Level, tag string, message
default:
message = levelString + "[" + xd(int(timestamp.Sub(f.BaseTime)/time.Second), 4) + "] " + message
}
return message + "\n"
if message[len(message)-1] != '\n' {
message += "\n"
}
return message
}
func (f Formatter) FormatWithSimple(ctx context.Context, level Level, tag string, message string, timestamp time.Time) (string, string) {
@ -137,7 +140,10 @@ func (f Formatter) FormatWithSimple(ctx context.Context, level Level, tag string
default:
message = levelString + "[" + xd(int(timestamp.Sub(f.BaseTime)/time.Second), 4) + "] " + message
}
return message + "\n", messageSimple
if message[len(message)-1] != '\n' {
message += "\n"
}
return message, messageSimple
}
func xd(value int, x int) string {