From d697c0a470c1819cc26e486515a8548378514dee Mon Sep 17 00:00:00 2001 From: "rick.chan" Date: Wed, 9 Aug 2023 08:34:11 +0000 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=97=A5=E5=BF=97=E6=A0=BC?= =?UTF-8?q?=E5=BC=8F.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: rick.chan --- simplelog.go | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/simplelog.go b/simplelog.go index 8ffc34b..f0cf043 100644 --- a/simplelog.go +++ b/simplelog.go @@ -228,17 +228,25 @@ func (l *SimpleLog) Output(callDepth int, level int, format string, v ...interfa buf := l.popBuf() - if l.flag&Llevel > 0 { + if (l.flag&Llevel > 0) || (l.flag&Ltime > 0) || (l.flag&Lfile > 0) { buf = append(buf, '[') + } + + if l.flag&Llevel > 0 { buf = append(buf, LevelName[level]...) - buf = append(buf, "] "...) + } + + if (l.flag&Llevel > 0) && (l.flag&Ltime > 0) { + buf = append(buf, " | "...) } if l.flag&Ltime > 0 { now := time.Now().Format(TimeFormat) - buf = append(buf, '[') buf = append(buf, now...) - buf = append(buf, "] "...) + } + + if (l.flag&Ltime > 0) && (l.flag&Lfile > 0) { + buf = append(buf, " | "...) } if l.flag&Lfile > 0 { @@ -259,7 +267,10 @@ func (l *SimpleLog) Output(callDepth int, level int, format string, v ...interfa buf = append(buf, ':') buf = strconv.AppendInt(buf, int64(line), 10) - buf = append(buf, ' ') + + if (l.flag&Llevel > 0) || (l.flag&Ltime > 0) || (l.flag&Lfile > 0) { + buf = append(buf, "] "...) + } } buf = append(buf, s...)