Skip to content

Commit 9633dd0

Browse files
committed
Merge branch 'hieu/systemtest/tx' of https://github.com/cosmos/cosmos-sdk into hieu/systemtest/tx
2 parents 754a38e + b27e9fa commit 9633dd0

File tree

100 files changed

+1699
-1405
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

100 files changed

+1699
-1405
lines changed

api/cosmos/accounts/defaults/lockup/lockup.pulsar.go api/cosmos/accounts/defaults/lockup/v1/lockup.pulsar.go

+101-98
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/cosmos/accounts/defaults/lockup/query.pulsar.go api/cosmos/accounts/defaults/lockup/v1/query.pulsar.go

+257-255
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/cosmos/accounts/defaults/lockup/tx.pulsar.go api/cosmos/accounts/defaults/lockup/v1/tx.pulsar.go

+567-565
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

baseapp/baseapp.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ func (app *BaseApp) LastCommitID() storetypes.CommitID {
397397

398398
// LastBlockHeight returns the last committed block height.
399399
func (app *BaseApp) LastBlockHeight() int64 {
400-
return app.cms.LastCommitID().Version
400+
return app.cms.LatestVersion()
401401
}
402402

403403
// ChainID returns the chainID of the app.

client/cmd.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ func GetClientQueryContext(cmd *cobra.Command) (Context, error) {
345345
// - client.Context field pre-populated & flag not set: uses pre-populated value
346346
// - client.Context field pre-populated & flag set: uses set flag value
347347
func GetClientTxContext(cmd *cobra.Command) (Context, error) {
348-
ctx := GetClientContextFromCmd(cmd)
348+
ctx := GetClientContextFromCmd(cmd).WithOutput(cmd.OutOrStdout())
349349
return readTxCommandFlags(ctx, cmd.Flags())
350350
}
351351

client/cmd_test.go

+26
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package client_test
22

33
import (
4+
"bytes"
45
"context"
56
"fmt"
67
"testing"
@@ -137,3 +138,28 @@ func TestSetCmdClientContextHandler(t *testing.T) {
137138
})
138139
}
139140
}
141+
142+
func TestContext_usesCobraCommandOutput(t *testing.T) {
143+
var initCtx client.Context
144+
145+
cmd := &cobra.Command{
146+
PreRunE: func(cmd *cobra.Command, args []string) error {
147+
return client.SetCmdClientContextHandler(initCtx, cmd)
148+
},
149+
RunE: func(cmd *cobra.Command, _ []string) error {
150+
cctx, err := client.GetClientTxContext(cmd)
151+
if err != nil {
152+
return err
153+
}
154+
155+
return cctx.PrintString("hello")
156+
},
157+
}
158+
159+
var outBuf bytes.Buffer
160+
cmd.SetOutput(&outBuf)
161+
162+
require.NoError(t, cmd.Execute())
163+
164+
require.Equal(t, "hello", outBuf.String())
165+
}

client/v2/go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ require (
88
cosmossdk.io/depinject v1.0.0
99
cosmossdk.io/x/bank v0.0.0-20240226161501-23359a0b6d91
1010
cosmossdk.io/x/gov v0.0.0-20231113122742-912390d5fc4a
11-
cosmossdk.io/x/tx v0.13.3
11+
cosmossdk.io/x/tx v1.0.0-alpha.1
1212
github.com/cosmos/cosmos-proto v1.0.0-beta.5
1313
github.com/cosmos/cosmos-sdk v0.53.0
1414
github.com/spf13/cobra v1.8.1

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ require (
1515
cosmossdk.io/store v1.1.1-0.20240418092142-896cdf1971bc
1616
cosmossdk.io/x/bank v0.0.0-20240226161501-23359a0b6d91
1717
cosmossdk.io/x/staking v0.0.0-00010101000000-000000000000
18-
cosmossdk.io/x/tx v0.13.3
18+
cosmossdk.io/x/tx v1.0.0-alpha.1
1919
github.com/99designs/keyring v1.2.2
2020
github.com/bgentry/speakeasy v0.2.0
2121
github.com/cometbft/cometbft v1.0.0-rc1.0.20240908111210-ab0be101882f

log/CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ Each entry must include the Github issue reference in the following format:
2222

2323
## [Unreleased]
2424

25+
### Improvements
26+
27+
* [#22233](https://github.com/cosmos/cosmos-sdk/pull/22233) Use sonic json library for faster json handling
28+
2529
## [v1.4.1](https://github.com/cosmos/cosmos-sdk/releases/tag/log/v1.4.1) - 2024-08-16
2630

2731
* [#21326](https://github.com/cosmos/cosmos-sdk/pull/21326) Avoid context key collision.

log/go.mod

+7-2
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,19 @@ module cosmossdk.io/log
33
go 1.20
44

55
require (
6+
github.com/bytedance/sonic v1.12.3
67
github.com/pkg/errors v0.9.1
78
github.com/rs/zerolog v1.33.0
8-
gotest.tools/v3 v3.5.1
99
)
1010

1111
require (
12-
github.com/google/go-cmp v0.6.0 // indirect
12+
github.com/bytedance/sonic/loader v0.2.0 // indirect
13+
github.com/cloudwego/base64x v0.1.4 // indirect
14+
github.com/cloudwego/iasm v0.2.0 // indirect
15+
github.com/klauspost/cpuid/v2 v2.0.9 // indirect
1316
github.com/mattn/go-colorable v0.1.13 // indirect
1417
github.com/mattn/go-isatty v0.0.20 // indirect
18+
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
19+
golang.org/x/arch v0.0.0-20210923205945-b76863e36670 // indirect
1520
golang.org/x/sys v0.22.0 // indirect
1621
)

log/go.sum

+34-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,20 @@
1+
github.com/bytedance/sonic v1.12.3 h1:W2MGa7RCU1QTeYRTPE3+88mVC0yXmsRQRChiyVocVjU=
2+
github.com/bytedance/sonic v1.12.3/go.mod h1:B8Gt/XvtZ3Fqj+iSKMypzymZxw/FVwgIGKzMzT9r/rk=
3+
github.com/bytedance/sonic/loader v0.1.1/go.mod h1:ncP89zfokxS5LZrJxl5z0UJcsk4M4yY2JpfqGeCtNLU=
4+
github.com/bytedance/sonic/loader v0.2.0 h1:zNprn+lsIP06C/IqCHs3gPQIvnvpKbbxyXQP1iU4kWM=
5+
github.com/bytedance/sonic/loader v0.2.0/go.mod h1:ncP89zfokxS5LZrJxl5z0UJcsk4M4yY2JpfqGeCtNLU=
6+
github.com/cloudwego/base64x v0.1.4 h1:jwCgWpFanWmN8xoIUHa2rtzmkd5J2plF/dnLS6Xd/0Y=
7+
github.com/cloudwego/base64x v0.1.4/go.mod h1:0zlkT4Wn5C6NdauXdJRhSKRlJvmclQ1hhJgA0rcu/8w=
8+
github.com/cloudwego/iasm v0.2.0 h1:1KNIy1I1H9hNNFEEH3DVnI4UujN+1zjpuk6gwHLTssg=
9+
github.com/cloudwego/iasm v0.2.0/go.mod h1:8rXZaNYT2n95jn+zTI1sDr+IgcD2GVs0nlbbQPiEFhY=
110
github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
11+
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
12+
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
13+
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
214
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
3-
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
4-
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
15+
github.com/klauspost/cpuid/v2 v2.0.9 h1:lgaqFMSdTdQYdZ04uHyN2d/eKdOMyi2YLSvlQIBFYa4=
16+
github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=
17+
github.com/knz/go-libedit v1.10.1/go.mod h1:MZTVkCWyz0oBc7JOWP3wNAzd002ZbM/5hgShxwh4x8M=
518
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
619
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
720
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
@@ -10,13 +23,30 @@ github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWE
1023
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
1124
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
1225
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
26+
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
27+
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
1328
github.com/rs/xid v1.5.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg=
1429
github.com/rs/zerolog v1.33.0 h1:1cU2KZkvPxNyfgEmhHAz/1A9Bz+llsdYzklWFzgp0r8=
1530
github.com/rs/zerolog v1.33.0/go.mod h1:/7mN4D5sKwJLZQ2b/znpjC3/GQWY/xaDXUM0kKWRHss=
31+
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
32+
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
33+
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
34+
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
35+
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
36+
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
37+
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
38+
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
39+
github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI=
40+
github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08=
41+
golang.org/x/arch v0.0.0-20210923205945-b76863e36670 h1:18EFjUmQOcUvxNYSkA6jO9VAiXCnxFY6NyDX0bHDmkU=
42+
golang.org/x/arch v0.0.0-20210923205945-b76863e36670/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8=
1643
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
1744
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
1845
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
1946
golang.org/x/sys v0.22.0 h1:RI27ohtqKCnwULzJLqkv897zojh5/DwS/ENaMzUOaWI=
2047
golang.org/x/sys v0.22.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
21-
gotest.tools/v3 v3.5.1 h1:EENdUnS3pdur5nybKYIh2Vfgc8IUNBjxDPSjtiJcOzU=
22-
gotest.tools/v3 v3.5.1/go.mod h1:isy3WKz7GK6uNw/sbHzfKBLvlvXwUyV06n6brMxxopU=
48+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
49+
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
50+
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
51+
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
52+
nullprogram.com/x/optparse v1.0.0/go.mod h1:KdyPE+Igbe0jQUrVfMqDMeJQIJZEuyV7pjYmp6pbG50=

log/level_test.go

+68-26
Original file line numberDiff line numberDiff line change
@@ -3,46 +3,88 @@ package log_test
33
import (
44
"testing"
55

6-
"gotest.tools/v3/assert"
7-
86
"cosmossdk.io/log"
97
)
108

119
func TestParseLogLevel(t *testing.T) {
1210
_, err := log.ParseLogLevel("")
13-
assert.Error(t, err, "empty log level")
11+
if err == nil {
12+
t.Errorf("expected error for empty log level, got nil")
13+
}
1414

1515
level := "consensus:foo,mempool:debug,*:error"
1616
_, err = log.ParseLogLevel(level)
17-
assert.Error(t, err, "invalid log level foo in log level list [consensus:foo mempool:debug *:error]")
17+
if err == nil {
18+
t.Errorf("expected error for invalid log level foo in log level list [consensus:foo mempool:debug *:error], got nil")
19+
}
1820

1921
level = "consensus:debug,mempool:debug,*:error"
2022
filter, err := log.ParseLogLevel(level)
21-
assert.NilError(t, err)
22-
assert.Assert(t, filter != nil)
23-
24-
assert.Assert(t, !filter("consensus", "debug"))
25-
assert.Assert(t, !filter("consensus", "info"))
26-
assert.Assert(t, !filter("consensus", "error"))
27-
assert.Assert(t, !filter("mempool", "debug"))
28-
assert.Assert(t, !filter("mempool", "info"))
29-
assert.Assert(t, !filter("mempool", "error"))
30-
assert.Assert(t, !filter("state", "error"))
31-
assert.Assert(t, !filter("server", "panic"))
32-
33-
assert.Assert(t, filter("server", "debug"))
34-
assert.Assert(t, filter("state", "debug"))
35-
assert.Assert(t, filter("state", "info"))
23+
if err != nil {
24+
t.Errorf("unexpected error: %v", err)
25+
}
26+
if filter == nil {
27+
t.Fatalf("expected non-nil filter, got nil")
28+
}
29+
30+
if filter("consensus", "debug") {
31+
t.Errorf("expected filter to return false for consensus:debug")
32+
}
33+
if filter("consensus", "info") {
34+
t.Errorf("expected filter to return false for consensus:info")
35+
}
36+
if filter("consensus", "error") {
37+
t.Errorf("expected filter to return false for consensus:error")
38+
}
39+
if filter("mempool", "debug") {
40+
t.Errorf("expected filter to return false for mempool:debug")
41+
}
42+
if filter("mempool", "info") {
43+
t.Errorf("expected filter to return false for mempool:info")
44+
}
45+
if filter("mempool", "error") {
46+
t.Errorf("expected filter to return false for mempool:error")
47+
}
48+
if filter("state", "error") {
49+
t.Errorf("expected filter to return false for state:error")
50+
}
51+
if filter("server", "panic") {
52+
t.Errorf("expected filter to return false for server:panic")
53+
}
54+
55+
if !filter("server", "debug") {
56+
t.Errorf("expected filter to return true for server:debug")
57+
}
58+
if !filter("state", "debug") {
59+
t.Errorf("expected filter to return true for state:debug")
60+
}
61+
if !filter("state", "info") {
62+
t.Errorf("expected filter to return true for state:info")
63+
}
3664

3765
level = "error"
3866
filter, err = log.ParseLogLevel(level)
39-
assert.NilError(t, err)
40-
assert.Assert(t, filter != nil)
67+
if err != nil {
68+
t.Errorf("unexpected error: %v", err)
69+
}
70+
if filter == nil {
71+
t.Fatalf("expected non-nil filter, got nil")
72+
}
4173

42-
assert.Assert(t, !filter("state", "error"))
43-
assert.Assert(t, !filter("consensus", "error"))
74+
if filter("state", "error") {
75+
t.Errorf("expected filter to return false for state:error")
76+
}
77+
if filter("consensus", "error") {
78+
t.Errorf("expected filter to return false for consensus:error")
79+
}
4480

45-
assert.Assert(t, filter("consensus", "debug"))
46-
assert.Assert(t, filter("consensus", "info"))
47-
assert.Assert(t, filter("state", "debug"))
81+
if !filter("consensus", "debug") {
82+
t.Errorf("expected filter to return true for consensus:debug")
83+
}
84+
if !filter("consensus", "info") {
85+
t.Errorf("expected filter to return true for consensus:info")
86+
}
87+
if !filter("state", "debug") {
88+
t.Errorf("expected filter to return true for state:debug")
89+
}
4890
}

log/logger.go

+6-4
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"fmt"
77
"io"
88

9+
"github.com/bytedance/sonic"
910
"github.com/pkg/errors"
1011
"github.com/rs/zerolog"
1112
"github.com/rs/zerolog/pkgerrors"
@@ -15,13 +16,13 @@ func init() {
1516
zerolog.InterfaceMarshalFunc = func(i any) ([]byte, error) {
1617
switch v := i.(type) {
1718
case json.Marshaler:
18-
return json.Marshal(i)
19+
return sonic.Marshal(i)
1920
case encoding.TextMarshaler:
20-
return json.Marshal(i)
21+
return sonic.Marshal(i)
2122
case fmt.Stringer:
22-
return json.Marshal(v.String())
23+
return sonic.Marshal(v.String())
2324
default:
24-
return json.Marshal(i)
25+
return sonic.Marshal(i)
2526
}
2627
}
2728
}
@@ -112,6 +113,7 @@ func NewLogger(dst io.Writer, options ...Option) Logger {
112113
}
113114

114115
logger := zerolog.New(output)
116+
115117
if logCfg.StackTrace {
116118
zerolog.ErrorStackMarshaler = func(err error) interface{} {
117119
return pkgerrors.MarshalStack(errors.WithStack(err))

log/logger_test.go

+25-20
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,10 @@ import (
77
"testing"
88

99
"github.com/rs/zerolog"
10-
"gotest.tools/v3/assert"
1110

1211
"cosmossdk.io/log"
1312
)
1413

15-
func TestLoggerOptionStackTrace(t *testing.T) {
16-
buf := new(bytes.Buffer)
17-
logger := log.NewLogger(buf, log.TraceOption(true), log.ColorOption(false))
18-
logger.Error("this log should be displayed", "error", inner())
19-
if strings.Count(buf.String(), "logger_test.go") != 1 {
20-
t.Fatalf("stack trace not found, got: %s", buf.String())
21-
}
22-
buf.Reset()
23-
24-
logger = log.NewLogger(buf, log.TraceOption(false), log.ColorOption(false))
25-
logger.Error("this log should be displayed", "error", inner())
26-
if strings.Count(buf.String(), "logger_test.go") > 0 {
27-
t.Fatalf("stack trace found, got: %s", buf.String())
28-
}
29-
}
30-
3114
func inner() error {
3215
return errors.New("seems we have an error here")
3316
}
@@ -46,11 +29,33 @@ func TestLoggerOptionHooks(t *testing.T) {
4629
)
4730
logger := log.NewLogger(buf, log.HooksOption(mockHook1, mockHook2), log.ColorOption(false))
4831
logger.Info("hello world")
49-
assert.Assert(t, strings.Contains(buf.String(), "mock_message1=true"))
50-
assert.Assert(t, strings.Contains(buf.String(), "mock_message2=true"))
32+
if !strings.Contains(buf.String(), "mock_message1=true") {
33+
t.Fatalf("expected mock_message1=true, got: %s", buf.String())
34+
}
35+
if !strings.Contains(buf.String(), "mock_message2=true") {
36+
t.Fatalf("expected mock_message2=true, got: %s", buf.String())
37+
}
5138

5239
buf.Reset()
5340
logger = log.NewLogger(buf, log.HooksOption(), log.ColorOption(false))
5441
logger.Info("hello world")
55-
assert.Assert(t, strings.Contains(buf.String(), "hello world"))
42+
if !strings.Contains(buf.String(), "hello world") {
43+
t.Fatalf("expected hello world, got: %s", buf.String())
44+
}
45+
}
46+
47+
func TestLoggerOptionStackTrace(t *testing.T) {
48+
buf := new(bytes.Buffer)
49+
logger := log.NewLogger(buf, log.TraceOption(true), log.ColorOption(false))
50+
logger.Error("this log should be displayed", "error", inner())
51+
if strings.Count(buf.String(), "logger_test.go") != 1 {
52+
t.Fatalf("stack trace not found, got: %s", buf.String())
53+
}
54+
buf.Reset()
55+
56+
logger = log.NewLogger(buf, log.TraceOption(false), log.ColorOption(false))
57+
logger.Error("this log should be displayed", "error", inner())
58+
if strings.Count(buf.String(), "logger_test.go") > 0 {
59+
t.Fatalf("stack trace found, got: %s", buf.String())
60+
}
5661
}

log/writer.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
package log
22

33
import (
4-
"encoding/json"
54
"fmt"
65
"io"
6+
7+
"github.com/bytedance/sonic"
78
)
89

910
// NewFilterWriter returns a writer that filters out all key/value pairs that do not match the filter.
@@ -28,7 +29,7 @@ func (fw *filterWriter) Write(p []byte) (n int, err error) {
2829
Module string `json:"module"`
2930
}
3031

31-
if err := json.Unmarshal(p, &event); err != nil {
32+
if err := sonic.Unmarshal(p, &event); err != nil {
3233
return 0, fmt.Errorf("failed to unmarshal event: %w", err)
3334
}
3435

0 commit comments

Comments
 (0)