diff --git a/baseapp/abci_test.go b/baseapp/abci_test.go index 1b6e205cf557..9cccf7a35ecf 100644 --- a/baseapp/abci_test.go +++ b/baseapp/abci_test.go @@ -15,6 +15,7 @@ import ( "github.com/stretchr/testify/require" errorsmod "cosmossdk.io/errors" + "cosmossdk.io/log" pruningtypes "cosmossdk.io/store/pruning/types" "cosmossdk.io/store/snapshots" snapshottypes "cosmossdk.io/store/snapshots/types" @@ -46,7 +47,7 @@ func TestABCI_Info(t *testing.T) { func TestABCI_InitChain(t *testing.T) { name := t.Name() db := dbm.NewMemDB() - logger := defaultLogger() + logger := log.NewTestLogger(t) app := baseapp.NewBaseApp(name, logger, db, nil) capKey := storetypes.NewKVStoreKey("main") @@ -126,8 +127,7 @@ func TestABCI_InitChain(t *testing.T) { func TestABCI_InitChain_WithInitialHeight(t *testing.T) { name := t.Name() db := dbm.NewMemDB() - logger := defaultLogger() - app := baseapp.NewBaseApp(name, logger, db, nil) + app := baseapp.NewBaseApp(name, log.NewTestLogger(t), db, nil) app.InitChain( abci.RequestInitChain{ @@ -142,8 +142,7 @@ func TestABCI_InitChain_WithInitialHeight(t *testing.T) { func TestABCI_BeginBlock_WithInitialHeight(t *testing.T) { name := t.Name() db := dbm.NewMemDB() - logger := defaultLogger() - app := baseapp.NewBaseApp(name, logger, db, nil) + app := baseapp.NewBaseApp(name, log.NewTestLogger(t), db, nil) app.InitChain( abci.RequestInitChain{ @@ -566,7 +565,6 @@ func TestABCI_ApplySnapshotChunk(t *testing.T) { func TestABCI_EndBlock(t *testing.T) { db := dbm.NewMemDB() name := t.Name() - logger := defaultLogger() cp := &cmtproto.ConsensusParams{ Block: &cmtproto.BlockParams{ @@ -574,7 +572,7 @@ func TestABCI_EndBlock(t *testing.T) { }, } - app := baseapp.NewBaseApp(name, logger, db, nil) + app := baseapp.NewBaseApp(name, log.NewTestLogger(t), db, nil) app.SetParamStore(¶mStore{db: dbm.NewMemDB()}) app.InitChain(abci.RequestInitChain{ ConsensusParams: cp, @@ -1211,7 +1209,7 @@ func TestABCI_Query(t *testing.T) { } func TestABCI_GetBlockRetentionHeight(t *testing.T) { - logger := defaultLogger() + logger := log.NewTestLogger(t) db := dbm.NewMemDB() name := t.Name() diff --git a/baseapp/baseapp_test.go b/baseapp/baseapp_test.go index 4874a371c6e2..47b06cf5ddf9 100644 --- a/baseapp/baseapp_test.go +++ b/baseapp/baseapp_test.go @@ -59,10 +59,9 @@ func NewBaseAppSuite(t *testing.T, opts ...func(*baseapp.BaseApp)) *BaseAppSuite baseapptestutil.RegisterInterfaces(cdc.InterfaceRegistry()) txConfig := authtx.NewTxConfig(cdc, authtx.DefaultSignModes) - logger := defaultLogger() db := dbm.NewMemDB() - app := baseapp.NewBaseApp(t.Name(), logger, db, txConfig.TxDecoder(), opts...) + app := baseapp.NewBaseApp(t.Name(), log.NewTestLogger(t), db, txConfig.TxDecoder(), opts...) require.Equal(t, t.Name(), app.Name()) app.SetInterfaceRegistry(cdc.InterfaceRegistry()) @@ -159,7 +158,7 @@ func NewBaseAppSuiteWithSnapshots(t *testing.T, cfg SnapshotsConfig, opts ...fun } func TestLoadVersion(t *testing.T) { - logger := defaultLogger() + logger := log.NewTestLogger(t) pruningOpt := baseapp.SetPruning(pruningtypes.NewPruningOptions(pruningtypes.PruningNothing)) db := dbm.NewMemDB() name := t.Name() @@ -284,7 +283,7 @@ func TestSetLoader(t *testing.T) { if tc.setLoader != nil { opts = append(opts, tc.setLoader) } - app := baseapp.NewBaseApp(t.Name(), defaultLogger(), db, nil, opts...) + app := baseapp.NewBaseApp(t.Name(), log.NewTestLogger(t), db, nil, opts...) app.MountStores(storetypes.NewKVStoreKey(tc.loadStoreKey)) err := app.LoadLatestVersion() require.Nil(t, err) @@ -302,11 +301,10 @@ func TestSetLoader(t *testing.T) { } func TestVersionSetterGetter(t *testing.T) { - logger := defaultLogger() pruningOpt := baseapp.SetPruning(pruningtypes.NewPruningOptions(pruningtypes.PruningDefault)) db := dbm.NewMemDB() name := t.Name() - app := baseapp.NewBaseApp(name, logger, db, nil, pruningOpt) + app := baseapp.NewBaseApp(name, log.NewTestLogger(t), db, nil, pruningOpt) require.Equal(t, "", app.Version()) res := app.Query(abci.RequestQuery{Path: "app/version"}) @@ -361,9 +359,8 @@ func TestOptionFunction(t *testing.T) { } } - logger := defaultLogger() db := dbm.NewMemDB() - bap := baseapp.NewBaseApp("starting name", logger, db, nil, testChangeNameHelper("new name")) + bap := baseapp.NewBaseApp("starting name", log.NewTestLogger(t), db, nil, testChangeNameHelper("new name")) require.Equal(t, bap.Name(), "new name", "BaseApp should have had name changed via option function") } @@ -543,10 +540,9 @@ func TestBaseAppAnteHandler(t *testing.T) { func TestABCI_CreateQueryContext(t *testing.T) { t.Parallel() - logger := defaultLogger() db := dbm.NewMemDB() name := t.Name() - app := baseapp.NewBaseApp(name, logger, db, nil) + app := baseapp.NewBaseApp(name, log.NewTestLogger(t), db, nil) app.BeginBlock(abci.RequestBeginBlock{Header: cmtproto.Header{Height: 1}}) app.Commit() diff --git a/baseapp/grpcrouter_test.go b/baseapp/grpcrouter_test.go index dede24b7bc1a..419c2e2845a0 100644 --- a/baseapp/grpcrouter_test.go +++ b/baseapp/grpcrouter_test.go @@ -58,7 +58,7 @@ func TestRegisterQueryServiceTwice(t *testing.T) { err := depinject.Inject(makeMinimalConfig(), &appBuilder) require.NoError(t, err) db := dbm.NewMemDB() - app := appBuilder.Build(log.NewLogger(), db, nil) + app := appBuilder.Build(log.NewTestLogger(t), db, nil) // First time registering service shouldn't panic. require.NotPanics(t, func() { diff --git a/baseapp/msg_service_router_test.go b/baseapp/msg_service_router_test.go index c361af9d667e..16f780e078f0 100644 --- a/baseapp/msg_service_router_test.go +++ b/baseapp/msg_service_router_test.go @@ -28,7 +28,7 @@ func TestRegisterMsgService(t *testing.T) { ) err := depinject.Inject(makeMinimalConfig(), &appBuilder, ®istry) require.NoError(t, err) - app := appBuilder.Build(log.NewLogger(), dbm.NewMemDB(), nil) + app := appBuilder.Build(log.NewTestLogger(t), dbm.NewMemDB(), nil) require.Panics(t, func() { testdata.RegisterMsgServer( @@ -57,7 +57,7 @@ func TestRegisterMsgServiceTwice(t *testing.T) { err := depinject.Inject(makeMinimalConfig(), &appBuilder, ®istry) require.NoError(t, err) db := dbm.NewMemDB() - app := appBuilder.Build(log.NewLogger(), db, nil) + app := appBuilder.Build(log.NewTestLogger(t), db, nil) testdata.RegisterInterfaces(registry) // First time registering service shouldn't panic. diff --git a/baseapp/utils_test.go b/baseapp/utils_test.go index 1ad067c7bcf6..7184506895f8 100644 --- a/baseapp/utils_test.go +++ b/baseapp/utils_test.go @@ -25,7 +25,6 @@ import ( dbm "github.com/cosmos/cosmos-db" "github.com/stretchr/testify/require" - "cosmossdk.io/log" "github.com/cosmos/cosmos-sdk/baseapp" baseapptestutil "github.com/cosmos/cosmos-sdk/baseapp/testutil" "github.com/cosmos/cosmos-sdk/client" @@ -52,14 +51,6 @@ import ( var ParamStoreKey = []byte("paramstore") -func defaultLogger() log.Logger { - if testing.Verbose() { - return log.NewLoggerWithKV("module", "baseapp/test") - } - - return log.NewNopLogger() -} - // GenesisStateWithSingleValidator initializes GenesisState with a single validator and genesis accounts // that also act as delegators. func GenesisStateWithSingleValidator(t *testing.T, codec codec.Codec, builder *runtime.AppBuilder) map[string]json.RawMessage { diff --git a/go.mod b/go.mod index b2a049b6b2db..401b37bdc961 100644 --- a/go.mod +++ b/go.mod @@ -154,6 +154,9 @@ require ( nhooyr.io/websocket v1.8.6 // indirect ) +// Short-lived replace for an outstanding PR of log. +replace cosmossdk.io/log => ./log + // Below are the long-lived replace of the Cosmos SDK replace ( // use cosmos fork of keyring diff --git a/log/CHANGELOG.md b/log/CHANGELOG.md index 16de809f2717..3bad706779d3 100644 --- a/log/CHANGELOG.md +++ b/log/CHANGELOG.md @@ -30,3 +30,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ # Changelog ## [Unreleased] + +### Improvements + +- [#15261](https://github.com/cosmos/cosmos-sdk/pull/15261): Provide `log.NewTestLogger(*testing.T)` function to create new log.Logger associated with a test diff --git a/log/testing.go b/log/testing.go index f9873ba32a99..7f231ac21318 100644 --- a/log/testing.go +++ b/log/testing.go @@ -1,20 +1,26 @@ package log -import "testing" +import "github.com/rs/zerolog" -// reuse the same logger across all tests -var _testingLogger Logger +// TestingT is the interface required for logging in tests. +// It is a subset of testing.T to avoid a direct dependency on the testing package. +type TestingT zerolog.TestingLog -func NewTestingLogger() Logger { - if _testingLogger != nil { - return _testingLogger +// NewTestLogger returns a logger that calls t.Log to write entries. +// +// If the logs may help debug a test failure, +// you may want to use NewTestLogger(t) in your test. +// Otherwise, use NewNopLogger(). +func NewTestLogger(t TestingT) Logger { + cw := zerolog.NewConsoleWriter() + cw.Out = zerolog.TestWriter{ + T: t, + // Normally one would use zerolog.ConsoleTestWriter + // to set the option on NewConsoleWriter, + // but the zerolog source for that is hardcoded to Frame=6. + // With Frame=6, all source locations are printed as "logger.go", + // but Frame=7 prints correct source locations. + Frame: 7, } - - if testing.Verbose() { - _testingLogger = NewLoggerWithKV(ModuleKey, "test") - } else { - _testingLogger = NewNopLogger() - } - - return _testingLogger + return NewCustomLogger(zerolog.New(cw)) } diff --git a/server/mock/app_test.go b/server/mock/app_test.go index afd60b399c6c..c3fcd15b4ec7 100644 --- a/server/mock/app_test.go +++ b/server/mock/app_test.go @@ -9,18 +9,30 @@ import ( cmtproto "github.com/cometbft/cometbft/proto/tendermint/types" "github.com/stretchr/testify/require" + "cosmossdk.io/log" + simtypes "github.com/cosmos/cosmos-sdk/types/simulation" genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types" ) -func TestInitApp(t *testing.T) { - app, closer, err := SetupApp() - // closer may need to be run, even when error in later stage - if closer != nil { - defer closer() - } +// SetupApp initializes a new application, +// failing t if initialization fails. +func SetupApp(t *testing.T) abci.Application { + t.Helper() + + logger := log.NewTestLogger(t) + + rootDir := t.TempDir() + + app, err := NewApp(rootDir, logger) require.NoError(t, err) + return app +} + +func TestInitApp(t *testing.T) { + app := SetupApp(t) + appState, err := AppGenState(nil, genutiltypes.AppGenesis{}, nil) require.NoError(t, err) @@ -42,12 +54,7 @@ func TestInitApp(t *testing.T) { } func TestDeliverTx(t *testing.T) { - app, closer, err := SetupApp() - // closer may need to be run, even when error in later stage - if closer != nil { - defer closer() - } - require.NoError(t, err) + app := SetupApp(t) key := "my-special-key" value := "top-secret-data!!" diff --git a/server/mock/helpers.go b/server/mock/helpers.go deleted file mode 100644 index ce0d6416a2e8..000000000000 --- a/server/mock/helpers.go +++ /dev/null @@ -1,29 +0,0 @@ -package mock - -import ( - "fmt" - "os" - - "cosmossdk.io/log" - abci "github.com/cometbft/cometbft/abci/types" -) - -// SetupApp returns an application as well as a clean-up function to be used to -// quickly setup a test case with an app. -func SetupApp() (abci.Application, func(), error) { - logger := log.NewTestingLogger() - rootDir, err := os.MkdirTemp("", "mock-sdk") - if err != nil { - return nil, nil, err - } - - cleanup := func() { - err := os.RemoveAll(rootDir) - if err != nil { - fmt.Printf("could not delete %s, had error %s\n", rootDir, err.Error()) - } - } - - app, err := NewApp(rootDir, logger) - return app, cleanup, err -} diff --git a/simapp/app_test.go b/simapp/app_test.go index 2238a857523b..a29c38c81cbd 100644 --- a/simapp/app_test.go +++ b/simapp/app_test.go @@ -41,9 +41,9 @@ import ( func TestSimAppExportAndBlockedAddrs(t *testing.T) { db := dbm.NewMemDB() - logger := log.NewLogger() + logger := log.NewTestLogger(t) app := NewSimappWithCustomOptions(t, false, SetupOptions{ - Logger: logger, + Logger: logger.With("instance", "first"), DB: db, AppOpts: simtestutil.NewAppOptionsWithFlagHome(t.TempDir()), }) @@ -66,20 +66,19 @@ func TestSimAppExportAndBlockedAddrs(t *testing.T) { app.Commit() - logger2 := log.NewLogger() // Making a new app object with the db, so that initchain hasn't been called - app2 := NewSimApp(logger2, db, nil, true, simtestutil.NewAppOptionsWithFlagHome(t.TempDir())) + app2 := NewSimApp(logger.With("instance", "second"), db, nil, true, simtestutil.NewAppOptionsWithFlagHome(t.TempDir())) _, err := app2.ExportAppStateAndValidators(false, []string{}, []string{}) require.NoError(t, err, "ExportAppStateAndValidators should not have an error") } func TestRunMigrations(t *testing.T) { db := dbm.NewMemDB() - logger := log.NewLogger() - app := NewSimApp(logger, db, nil, true, simtestutil.NewAppOptionsWithFlagHome(t.TempDir())) + logger := log.NewTestLogger(t) + app := NewSimApp(logger.With("instance", "simapp"), db, nil, true, simtestutil.NewAppOptionsWithFlagHome(t.TempDir())) // Create a new baseapp and configurator for the purpose of this test. - bApp := baseapp.NewBaseApp(app.Name(), logger, db, app.TxConfig().TxDecoder()) + bApp := baseapp.NewBaseApp(app.Name(), logger.With("instance", "baseapp"), db, app.TxConfig().TxDecoder()) bApp.SetCommitMultiStoreTracer(nil) bApp.SetInterfaceRegistry(app.InterfaceRegistry()) app.BaseApp = bApp @@ -216,8 +215,7 @@ func TestRunMigrations(t *testing.T) { func TestInitGenesisOnMigration(t *testing.T) { db := dbm.NewMemDB() - logger := log.NewLogger() - app := NewSimApp(logger, db, nil, true, simtestutil.NewAppOptionsWithFlagHome(t.TempDir())) + app := NewSimApp(log.NewTestLogger(t), db, nil, true, simtestutil.NewAppOptionsWithFlagHome(t.TempDir())) ctx := app.NewContext(true, cmtproto.Header{Height: app.LastBlockHeight()}) // Create a mock module. This module will serve as the new module we're @@ -259,9 +257,8 @@ func TestInitGenesisOnMigration(t *testing.T) { func TestUpgradeStateOnGenesis(t *testing.T) { db := dbm.NewMemDB() - logger := log.NewLogger() app := NewSimappWithCustomOptions(t, false, SetupOptions{ - Logger: logger, + Logger: log.NewTestLogger(t), DB: db, AppOpts: simtestutil.NewAppOptionsWithFlagHome(t.TempDir()), }) diff --git a/simapp/go.mod b/simapp/go.mod index 9f0080c34465..ba33f332a4cb 100644 --- a/simapp/go.mod +++ b/simapp/go.mod @@ -7,7 +7,7 @@ require ( cosmossdk.io/client/v2 v2.0.0-20230220152935-67f04e629623 cosmossdk.io/core v0.6.0 cosmossdk.io/depinject v1.0.0-alpha.3 - cosmossdk.io/log v0.0.0-20230227204852-3535ee51c728 + cosmossdk.io/log v0.0.0-20230303183710-74c894f12720 cosmossdk.io/math v1.0.0-beta.6.0.20230216172121-959ce49135e4 cosmossdk.io/store v0.0.0-20230227103508-bbe7f8a11b44 cosmossdk.io/tools/confix v0.0.0-20230120150717-4f6f6c00021f diff --git a/simapp/go.sum b/simapp/go.sum index 9091dfbd40c6..b9d3d315b7d2 100644 --- a/simapp/go.sum +++ b/simapp/go.sum @@ -200,8 +200,8 @@ cosmossdk.io/depinject v1.0.0-alpha.3 h1:6evFIgj//Y3w09bqOUOzEpFj5tsxBqdc5CfkO7z cosmossdk.io/depinject v1.0.0-alpha.3/go.mod h1:eRbcdQ7MRpIPEM5YUJh8k97nxHpYbc3sMUnEtt8HPWU= cosmossdk.io/errors v1.0.0-beta.7 h1:gypHW76pTQGVnHKo6QBkb4yFOJjC+sUGRc5Al3Odj1w= cosmossdk.io/errors v1.0.0-beta.7/go.mod h1:mz6FQMJRku4bY7aqS/Gwfcmr/ue91roMEKAmDUDpBfE= -cosmossdk.io/log v0.0.0-20230227204852-3535ee51c728 h1:OpmiiO3x9esYawh4WX7jLL0UzBoOfjZrx3SdM3l8lhE= -cosmossdk.io/log v0.0.0-20230227204852-3535ee51c728/go.mod h1:FZRNfYm6Jgp+toyDR8Ek1qrmNjdsDddEQnfATMbpGYg= +cosmossdk.io/log v0.0.0-20230303183710-74c894f12720 h1:yrSwsgagxMHe/cj5V0TRRxNyr1k1cshizqaOGU4McKE= +cosmossdk.io/log v0.0.0-20230303183710-74c894f12720/go.mod h1:ilL9YXutMQo36MS9CD1cFNUqqHadAtyf8+A2b2EqO5A= cosmossdk.io/math v1.0.0-beta.6.0.20230216172121-959ce49135e4 h1:/jnzJ9zFsL7qkV8LCQ1JH3dYHh2EsKZ3k8Mr6AqqiOA= cosmossdk.io/math v1.0.0-beta.6.0.20230216172121-959ce49135e4/go.mod h1:gUVtWwIzfSXqcOT+lBVz2jyjfua8DoBdzRsIyaUAT/8= cosmossdk.io/store v0.0.0-20230227103508-bbe7f8a11b44 h1:/pKsj/ApzO4+zMwpgLiPG5iakoHxziGpMiJcz4S+r4w= diff --git a/simapp/sim_test.go b/simapp/sim_test.go index 2a6688c25d47..0cd6cdc26ca5 100644 --- a/simapp/sim_test.go +++ b/simapp/sim_test.go @@ -339,7 +339,7 @@ func TestAppStateDeterminism(t *testing.T) { for j := 0; j < numTimesToRunPerSeed; j++ { var logger log.Logger if simcli.FlagVerboseValue { - logger = log.NewTestingLogger() + logger = log.NewTestLogger(t) } else { logger = log.NewNopLogger() } diff --git a/tests/e2e/server/export_test.go b/tests/e2e/server/export_test.go index 72a75736ae29..cafc09663932 100644 --- a/tests/e2e/server/export_test.go +++ b/tests/e2e/server/export_test.go @@ -154,10 +154,10 @@ func TestExportCmd_Output(t *testing.T) { func setupApp(t *testing.T, tempDir string) (*simapp.SimApp, context.Context, genutiltypes.AppGenesis, *cobra.Command) { t.Helper() + logger := log.NewTestLogger(t) err := createConfigFolder(tempDir) assert.NilError(t, err) - logger := log.NewLogger() db := dbm.NewMemDB() app := simapp.NewSimApp(logger, db, nil, true, simtestutil.NewAppOptionsWithFlagHome(tempDir)) diff --git a/tests/go.mod b/tests/go.mod index 09d6d633e119..371c16c55563 100644 --- a/tests/go.mod +++ b/tests/go.mod @@ -6,7 +6,7 @@ require ( cosmossdk.io/api v0.3.1 cosmossdk.io/depinject v1.0.0-alpha.3 cosmossdk.io/errors v1.0.0-beta.7 - cosmossdk.io/log v0.0.0-20230227204852-3535ee51c728 + cosmossdk.io/log v0.0.0-20230303183710-74c894f12720 cosmossdk.io/math v1.0.0-beta.6.0.20230216172121-959ce49135e4 cosmossdk.io/simapp v0.0.0-00010101000000-000000000000 cosmossdk.io/store v0.0.0-20230227103508-bbe7f8a11b44 diff --git a/tests/go.sum b/tests/go.sum index 4b0c8ba851ed..f731c8ed7b0a 100644 --- a/tests/go.sum +++ b/tests/go.sum @@ -198,8 +198,8 @@ cosmossdk.io/depinject v1.0.0-alpha.3 h1:6evFIgj//Y3w09bqOUOzEpFj5tsxBqdc5CfkO7z cosmossdk.io/depinject v1.0.0-alpha.3/go.mod h1:eRbcdQ7MRpIPEM5YUJh8k97nxHpYbc3sMUnEtt8HPWU= cosmossdk.io/errors v1.0.0-beta.7 h1:gypHW76pTQGVnHKo6QBkb4yFOJjC+sUGRc5Al3Odj1w= cosmossdk.io/errors v1.0.0-beta.7/go.mod h1:mz6FQMJRku4bY7aqS/Gwfcmr/ue91roMEKAmDUDpBfE= -cosmossdk.io/log v0.0.0-20230227204852-3535ee51c728 h1:OpmiiO3x9esYawh4WX7jLL0UzBoOfjZrx3SdM3l8lhE= -cosmossdk.io/log v0.0.0-20230227204852-3535ee51c728/go.mod h1:FZRNfYm6Jgp+toyDR8Ek1qrmNjdsDddEQnfATMbpGYg= +cosmossdk.io/log v0.0.0-20230303183710-74c894f12720 h1:yrSwsgagxMHe/cj5V0TRRxNyr1k1cshizqaOGU4McKE= +cosmossdk.io/log v0.0.0-20230303183710-74c894f12720/go.mod h1:ilL9YXutMQo36MS9CD1cFNUqqHadAtyf8+A2b2EqO5A= cosmossdk.io/math v1.0.0-beta.6.0.20230216172121-959ce49135e4 h1:/jnzJ9zFsL7qkV8LCQ1JH3dYHh2EsKZ3k8Mr6AqqiOA= cosmossdk.io/math v1.0.0-beta.6.0.20230216172121-959ce49135e4/go.mod h1:gUVtWwIzfSXqcOT+lBVz2jyjfua8DoBdzRsIyaUAT/8= cosmossdk.io/store v0.0.0-20230227103508-bbe7f8a11b44 h1:/pKsj/ApzO4+zMwpgLiPG5iakoHxziGpMiJcz4S+r4w= diff --git a/tools/cosmovisor/cmd/cosmovisor/version_test.go b/tools/cosmovisor/cmd/cosmovisor/version_test.go index 8f8188a2a82d..d42e3d6bb6fe 100644 --- a/tools/cosmovisor/cmd/cosmovisor/version_test.go +++ b/tools/cosmovisor/cmd/cosmovisor/version_test.go @@ -10,7 +10,7 @@ import ( ) func TestVersionCommand_Error(t *testing.T) { - logger := log.NewLoggerWithKV(log.ModuleKey, "cosmovisor") + logger := log.NewTestLogger(t).With(log.ModuleKey, "cosmovisor") rootCmd.SetArgs([]string{"version"}) diff --git a/tools/cosmovisor/go.mod b/tools/cosmovisor/go.mod index 53ab5faa9542..b97ba9dcdbd3 100644 --- a/tools/cosmovisor/go.mod +++ b/tools/cosmovisor/go.mod @@ -3,7 +3,7 @@ module cosmossdk.io/tools/cosmovisor go 1.20 require ( - cosmossdk.io/log v0.0.0-20230227204852-3535ee51c728 + cosmossdk.io/log v0.0.0-20230303183710-74c894f12720 cosmossdk.io/x/upgrade v0.0.0-20230227110325-294ef34f396f github.com/otiai10/copy v1.9.0 github.com/rs/zerolog v1.29.0 diff --git a/tools/cosmovisor/go.sum b/tools/cosmovisor/go.sum index a15f8ff28668..9b1435cc999d 100644 --- a/tools/cosmovisor/go.sum +++ b/tools/cosmovisor/go.sum @@ -198,8 +198,8 @@ cosmossdk.io/depinject v1.0.0-alpha.3 h1:6evFIgj//Y3w09bqOUOzEpFj5tsxBqdc5CfkO7z cosmossdk.io/depinject v1.0.0-alpha.3/go.mod h1:eRbcdQ7MRpIPEM5YUJh8k97nxHpYbc3sMUnEtt8HPWU= cosmossdk.io/errors v1.0.0-beta.7 h1:gypHW76pTQGVnHKo6QBkb4yFOJjC+sUGRc5Al3Odj1w= cosmossdk.io/errors v1.0.0-beta.7/go.mod h1:mz6FQMJRku4bY7aqS/Gwfcmr/ue91roMEKAmDUDpBfE= -cosmossdk.io/log v0.0.0-20230227204852-3535ee51c728 h1:OpmiiO3x9esYawh4WX7jLL0UzBoOfjZrx3SdM3l8lhE= -cosmossdk.io/log v0.0.0-20230227204852-3535ee51c728/go.mod h1:FZRNfYm6Jgp+toyDR8Ek1qrmNjdsDddEQnfATMbpGYg= +cosmossdk.io/log v0.0.0-20230303183710-74c894f12720 h1:yrSwsgagxMHe/cj5V0TRRxNyr1k1cshizqaOGU4McKE= +cosmossdk.io/log v0.0.0-20230303183710-74c894f12720/go.mod h1:ilL9YXutMQo36MS9CD1cFNUqqHadAtyf8+A2b2EqO5A= cosmossdk.io/math v1.0.0-beta.6.0.20230216172121-959ce49135e4 h1:/jnzJ9zFsL7qkV8LCQ1JH3dYHh2EsKZ3k8Mr6AqqiOA= cosmossdk.io/math v1.0.0-beta.6.0.20230216172121-959ce49135e4/go.mod h1:gUVtWwIzfSXqcOT+lBVz2jyjfua8DoBdzRsIyaUAT/8= cosmossdk.io/store v0.0.0-20230227103508-bbe7f8a11b44 h1:/pKsj/ApzO4+zMwpgLiPG5iakoHxziGpMiJcz4S+r4w= diff --git a/x/upgrade/go.mod b/x/upgrade/go.mod index 5e50f000e850..6a85eea64c78 100644 --- a/x/upgrade/go.mod +++ b/x/upgrade/go.mod @@ -7,7 +7,7 @@ require ( cosmossdk.io/core v0.6.0 cosmossdk.io/depinject v1.0.0-alpha.3 cosmossdk.io/errors v1.0.0-beta.7 - cosmossdk.io/log v0.0.0-20230227204852-3535ee51c728 + cosmossdk.io/log v0.0.0-20230303183710-74c894f12720 cosmossdk.io/store v0.0.0-20230227103508-bbe7f8a11b44 github.com/cometbft/cometbft v0.37.0-rc4 github.com/cosmos/cosmos-db v1.0.0-rc.1 diff --git a/x/upgrade/go.sum b/x/upgrade/go.sum index 0ed608d9a260..307a0cabee78 100644 --- a/x/upgrade/go.sum +++ b/x/upgrade/go.sum @@ -198,8 +198,8 @@ cosmossdk.io/depinject v1.0.0-alpha.3 h1:6evFIgj//Y3w09bqOUOzEpFj5tsxBqdc5CfkO7z cosmossdk.io/depinject v1.0.0-alpha.3/go.mod h1:eRbcdQ7MRpIPEM5YUJh8k97nxHpYbc3sMUnEtt8HPWU= cosmossdk.io/errors v1.0.0-beta.7 h1:gypHW76pTQGVnHKo6QBkb4yFOJjC+sUGRc5Al3Odj1w= cosmossdk.io/errors v1.0.0-beta.7/go.mod h1:mz6FQMJRku4bY7aqS/Gwfcmr/ue91roMEKAmDUDpBfE= -cosmossdk.io/log v0.0.0-20230227204852-3535ee51c728 h1:OpmiiO3x9esYawh4WX7jLL0UzBoOfjZrx3SdM3l8lhE= -cosmossdk.io/log v0.0.0-20230227204852-3535ee51c728/go.mod h1:FZRNfYm6Jgp+toyDR8Ek1qrmNjdsDddEQnfATMbpGYg= +cosmossdk.io/log v0.0.0-20230303183710-74c894f12720 h1:yrSwsgagxMHe/cj5V0TRRxNyr1k1cshizqaOGU4McKE= +cosmossdk.io/log v0.0.0-20230303183710-74c894f12720/go.mod h1:ilL9YXutMQo36MS9CD1cFNUqqHadAtyf8+A2b2EqO5A= cosmossdk.io/math v1.0.0-beta.6.0.20230216172121-959ce49135e4 h1:/jnzJ9zFsL7qkV8LCQ1JH3dYHh2EsKZ3k8Mr6AqqiOA= cosmossdk.io/math v1.0.0-beta.6.0.20230216172121-959ce49135e4/go.mod h1:gUVtWwIzfSXqcOT+lBVz2jyjfua8DoBdzRsIyaUAT/8= cosmossdk.io/store v0.0.0-20230227103508-bbe7f8a11b44 h1:/pKsj/ApzO4+zMwpgLiPG5iakoHxziGpMiJcz4S+r4w= diff --git a/x/upgrade/types/storeloader_test.go b/x/upgrade/types/storeloader_test.go index 16c27bd3c428..26926a4e0be2 100644 --- a/x/upgrade/types/storeloader_test.go +++ b/x/upgrade/types/storeloader_test.go @@ -26,10 +26,6 @@ func useUpgradeLoader(height int64, upgrades *storetypes.StoreUpgrades) func(*ba } } -func defaultLogger() log.Logger { - return log.NewLogger() -} - func initStore(t *testing.T, db dbm.DB, storeKey string, k, v []byte) { rs := rootmulti.NewStore(db, log.NewNopLogger(), metrics.NewNoOpMetrics()) rs.SetPruning(pruningtypes.NewPruningOptions(pruningtypes.PruningNothing)) @@ -121,7 +117,9 @@ func TestSetLoader(t *testing.T) { // load the app with the existing db opts := []func(*baseapp.BaseApp){baseapp.SetPruning(pruningtypes.NewPruningOptions(pruningtypes.PruningNothing))} - origapp := baseapp.NewBaseApp(t.Name(), defaultLogger(), db, nil, opts...) + logger := log.NewTestLogger(t) + + origapp := baseapp.NewBaseApp(t.Name(), logger.With("instance", "orig"), db, nil, opts...) origapp.MountStores(storetypes.NewKVStoreKey(tc.origStoreKey)) err := origapp.LoadLatestVersion() require.Nil(t, err) @@ -137,7 +135,7 @@ func TestSetLoader(t *testing.T) { } // load the new app with the original app db - app := baseapp.NewBaseApp(t.Name(), defaultLogger(), db, nil, opts...) + app := baseapp.NewBaseApp(t.Name(), logger.With("instance", "new"), db, nil, opts...) app.MountStores(storetypes.NewKVStoreKey(tc.loadStoreKey)) err = app.LoadLatestVersion() require.Nil(t, err)