From c31987b26dc33a488293555c39b52b324f1ae6bb Mon Sep 17 00:00:00 2001 From: caixw Date: Fri, 24 Nov 2023 13:12:46 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20Recorder.Printf=20=E7=8E=B0?= =?UTF-8?q?=E5=9C=A8=E4=BC=9A=E5=B0=9D=E8=AF=95=E7=BF=BB=E8=AF=91=E5=86=85?= =?UTF-8?q?=E5=AE=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- record.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/record.go b/record.go index 8b777b4..2646205 100644 --- a/record.go +++ b/record.go @@ -3,6 +3,7 @@ package logs import ( + "fmt" "runtime" "sync" "time" @@ -62,6 +63,8 @@ type ( // 输出一条日志信息 // + // 如果指定了 [WithLocale],那么该方法会尝试翻译些条内容。 + // // NOTE: 此操作之后,当前对象不再可用! Printf(format string, v ...any) } @@ -230,8 +233,14 @@ func (e *Record) DepthPrint(depth int, v ...any) *Record { // // 如果 [Logs.HasLocation] 为 false,那么 depth 将不起实际作用。 func (e *Record) DepthPrintf(depth int, format string, v ...any) *Record { - replaceLocaleString(e.logs.printer, v) - e.AppendMessage = func(b *Buffer) { b.Appendf(format, v...) } + var s string + if e.logs.printer == nil { + s = fmt.Sprintf(format, v...) + } else { + s = e.logs.printer.Sprintf(format, v...) + } + + e.AppendMessage = func(b *Buffer) { b.AppendString(s) } return e.initLocationCreated(depth) }