diff --git a/core/logx/logs.go b/core/logx/logs.go index a9116806..aa72fe73 100644 --- a/core/logx/logs.go +++ b/core/logx/logs.go @@ -199,11 +199,8 @@ 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) - } + writer.Store(w) } // SetUp sets up the logx. If already set up, just return nil. diff --git a/core/logx/logs_test.go b/core/logx/logs_test.go index e3aadf93..89faeb16 100644 --- a/core/logx/logs_test.go +++ b/core/logx/logs_test.go @@ -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)) - assert.True(t, writer.Load() == nopWriter{}) + mocked := new(mockWriter) + SetWriter(mocked) + assert.Equal(t, mocked, writer.Load()) } func TestWithGzip(t *testing.T) { diff --git a/zrpc/internal/serverinterceptors/statinterceptor.go b/zrpc/internal/serverinterceptors/statinterceptor.go index 05cd04b4..37ff6025 100644 --- a/zrpc/internal/serverinterceptors/statinterceptor.go +++ b/zrpc/internal/serverinterceptors/statinterceptor.go @@ -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)) }