diff --git a/core/logx/logs.go b/core/logx/logs.go index 34bb1112..81ee4e3e 100644 --- a/core/logx/logs.go +++ b/core/logx/logs.go @@ -33,7 +33,7 @@ const ( ) const ( - jsonEncodingType = iota + jsonEncodingType uint32 = iota plainEncodingType jsonEncoding = "json" @@ -137,9 +137,9 @@ func SetUp(c LogConf) error { } switch c.Encoding { case plainEncoding: - encoding = plainEncodingType + setEncoding(plainEncodingType) default: - encoding = jsonEncodingType + setEncoding(jsonEncodingType) } switch c.Mode { @@ -666,3 +666,7 @@ func (lw logWriter) Write(data []byte) (int, error) { lw.logger.Print(string(data)) return len(data), nil } + +func setEncoding(encodingType uint32) { + atomic.StoreUint32(&encoding, encodingType) +} diff --git a/core/logx/tracelogger_test.go b/core/logx/tracelogger_test.go index 7da8d0dd..1427e736 100644 --- a/core/logx/tracelogger_test.go +++ b/core/logx/tracelogger_test.go @@ -84,9 +84,9 @@ func TestTraceInfo(t *testing.T) { func TestTraceInfoConsole(t *testing.T) { old := encoding - encoding = plainEncodingType + setEncoding(jsonEncodingType) defer func() { - encoding = old + setEncoding(old) }() var buf mockWriter diff --git a/tools/goctl/go.mod b/tools/goctl/go.mod index 5e4ffd7f..9adc3c44 100644 --- a/tools/goctl/go.mod +++ b/tools/goctl/go.mod @@ -12,6 +12,6 @@ require ( github.com/stretchr/testify v1.7.0 github.com/urfave/cli v1.22.5 github.com/zeromicro/antlr v0.0.1 - github.com/zeromicro/ddl-parser v1.0.2 + github.com/zeromicro/ddl-parser v1.0.3 github.com/zeromicro/go-zero v1.3.0 )