@ -199,12 +199,9 @@ func SetLevel(level uint32) {
}
// SetWriter sets the logging writer. It can be used to customize the logging.
// Call Reset before calling SetWriter again.
func SetWriter(w Writer) {
if writer.Load() == nil {
writer.Store(w)
// SetUp sets up the logx. If already set up, just return nil.
// we allow SetUp to be called multiple times, because for example
@ -603,8 +603,9 @@ func TestSetWriter(t *testing.T) {
SetWriter(nopWriter{})
assert.NotNil(t, writer.Load())
assert.True(t, writer.Load() == nopWriter{})
SetWriter(new(mockWriter))
mocked := new(mockWriter)
SetWriter(mocked)
assert.Equal(t, mocked, writer.Load())
func TestWithGzip(t *testing.T) {
@ -69,8 +69,7 @@ func logDuration(ctx context.Context, method string, req interface{}, duration t
if err != nil {
logx.WithContext(ctx).Errorf("%s - %s", addr, err.Error())
} else if duration > slowThreshold.Load() {
logger.Slowf("[RPC] slowcall - %s - %s - %s",
addr, method, string(content))
logger.Slowf("[RPC] slowcall - %s - %s - %s", addr, method, string(content))
} else {
logger.Infof("%s - %s - %s", addr, method, string(content))