add Debugfn and Infofn to logx/logc #4595 (#4598)

This commit is contained in:
Devin
2025-01-25 22:21:50 +08:00
committed by GitHub
parent 7d05a4bc93
commit 64e8c94198
5 changed files with 80 additions and 1 deletions

View File

@@ -257,7 +257,26 @@ func TestStructedLogDebugv(t *testing.T) {
Debugv(fmt.Sprint(v...))
})
}
func TestStructedLogDebugfn(t *testing.T) {
w := new(mockWriter)
old := writer.Swap(w)
defer writer.Store(old)
doTestStructedLog(t, levelDebug, w, func(v ...any) {
Debugfn(func() string {
return fmt.Sprint(v...)
})
})
}
func TestDebugfnWithInfoLevel(t *testing.T) {
called := false
SetLevel(InfoLevel)
defer SetLevel(DebugLevel)
Debugfn(func() string {
called = true
return "long time log"
})
assert.False(t, called)
}
func TestStructedLogDebugw(t *testing.T) {
w := new(mockWriter)
old := writer.Swap(w)
@@ -450,6 +469,27 @@ func TestStructedLogInfoConsoleText(t *testing.T) {
Info(fmt.Sprint(v...))
})
}
func TestStructedInfofn(t *testing.T) {
w := new(mockWriter)
old := writer.Swap(w)
defer writer.Store(old)
doTestStructedLog(t, levelInfo, w, func(v ...any) {
Infofn(func() string {
return fmt.Sprint(v...)
})
})
}
func TestInfofnWithErrorLevel(t *testing.T) {
called := false
SetLevel(ErrorLevel)
defer SetLevel(DebugLevel)
Infofn(func() string {
called = true
return "info log"
})
assert.False(t, called)
}
func TestStructedLogSlow(t *testing.T) {
w := new(mockWriter)