Skip to content

Commit

Permalink
refactor: Recorder.Printf 现在会尝试翻译内容
Browse files Browse the repository at this point in the history
  • Loading branch information
caixw committed Nov 24, 2023
1 parent 8998dc5 commit c31987b
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions record.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
package logs

import (
"fmt"
"runtime"
"sync"
"time"
Expand Down Expand Up @@ -62,6 +63,8 @@ type (

// 输出一条日志信息
//
// 如果指定了 [WithLocale],那么该方法会尝试翻译些条内容。
//
// NOTE: 此操作之后,当前对象不再可用!
Printf(format string, v ...any)
}
Expand Down Expand Up @@ -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)
}

Expand Down

0 comments on commit c31987b

Please sign in to comment.