Skip to content

Commit 70cd2aa

Browse files
committed
Logf works without argument
1 parent 5894459 commit 70cd2aa

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

try/out.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,17 @@ type (
4040
//
4141
// error sending response: UDP not listening
4242
func (o *Result) Logf(a ...any) *Result {
43-
if o.Err == nil || len(a) == 0 {
43+
if o.Err == nil {
4444
return o
4545
}
46-
f, isFormat := a[0].(string)
47-
if isFormat {
48-
s := fmt.Sprintf(f+": %v", append(a[1:], o.Err)...)
49-
_ = handler.LogOutput(2, s)
46+
s := o.Err.Error()
47+
if len(a) != 0 {
48+
f, isFormat := a[0].(string)
49+
if isFormat {
50+
s = fmt.Sprintf(f+": %v", append(a[1:], o.Err)...)
51+
}
5052
}
53+
_ = handler.LogOutput(2, s)
5154
return o
5255
}
5356

try/result2_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@ func ExampleResult2_Logf() {
2121
err2.SetLogTracer(os.Stdout)
2222

2323
countSomething := func(s1, s2 string) (int, int) {
24-
r := try.Out2(convTwoStr(s1, s2)).Logf("not number").Def2(10, 10)
24+
r := try.Out2(convTwoStr(s1, s2)).Logf().Def2(10, 10)
2525
v1, v2 := r.Val1, r.Val2
2626
return v1 + v2, v2
2727
}
2828
_, _ = countSomething("1", "2")
2929
num1, num2 := countSomething("WRONG", "2")
3030
fmt.Printf("results: %d, %d", num1, num2)
3131
err2.SetLogTracer(nil)
32-
// Output: not number: testing run example: strconv.Atoi: parsing "WRONG": invalid syntax
32+
// Output: testing run example: strconv.Atoi: parsing "WRONG": invalid syntax
3333
// results: 20, 10
3434
}

0 commit comments

Comments
 (0)