From 7bc7b72c613a1e55b087df4df081bdd9b676b8d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=96=E7=95=8C?= Date: Fri, 22 Jul 2022 14:28:29 +0800 Subject: [PATCH] Fix log format --- log/default.go | 2 +- log/format.go | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/log/default.go b/log/default.go index d8014489..a8aaff87 100644 --- a/log/default.go +++ b/log/default.go @@ -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) } diff --git a/log/format.go b/log/format.go index ef69d821..96e0364b 100644 --- a/log/format.go +++ b/log/format.go @@ -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 {