feat: support %w in logx.Errorf (#1278)
This commit is contained in:
@@ -217,7 +217,7 @@ func ErrorCaller(callDepth int, v ...interface{}) {
|
|||||||
|
|
||||||
// ErrorCallerf writes v with context in format into error log.
|
// ErrorCallerf writes v with context in format into error log.
|
||||||
func ErrorCallerf(callDepth int, format string, v ...interface{}) {
|
func ErrorCallerf(callDepth int, format string, v ...interface{}) {
|
||||||
errorTextSync(fmt.Sprintf(format, v...), callDepth+callerInnerDepth)
|
errorTextSync(fmt.Errorf(format, v...).Error(), callDepth+callerInnerDepth)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Errorf writes v with format into error log.
|
// Errorf writes v with format into error log.
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package logx
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
@@ -242,6 +243,16 @@ func TestSetLevelWithDuration(t *testing.T) {
|
|||||||
assert.Equal(t, 0, writer.builder.Len())
|
assert.Equal(t, 0, writer.builder.Len())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestErrorfWithWrappedError(t *testing.T) {
|
||||||
|
SetLevel(ErrorLevel)
|
||||||
|
const message = "there"
|
||||||
|
writer := new(mockWriter)
|
||||||
|
errorLog = writer
|
||||||
|
atomic.StoreUint32(&initialized, 1)
|
||||||
|
Errorf("hello %w", errors.New(message))
|
||||||
|
assert.True(t, strings.Contains(writer.builder.String(), "hello there"))
|
||||||
|
}
|
||||||
|
|
||||||
func TestMustNil(t *testing.T) {
|
func TestMustNil(t *testing.T) {
|
||||||
Must(nil)
|
Must(nil)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user