-
Notifications
You must be signed in to change notification settings - Fork 3.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(log): remove core dependency and update core interface to be dependency free #21045
Conversation
Important Review skippedMore than 25% of the files skipped due to max files limit. The review is being skipped to prevent a low-quality review. 20 files out of 77 files are above the max files limit of 50. Please upgrade to Pro plan to get higher limits. You can disable this status message by setting the WalkthroughWalkthroughThe changes enhance the logging system in the Cosmos SDK by restructuring the logging interfaces, introducing Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant LoggerV2
participant LoggerBase
Client->>LoggerV2: Create Logger
LoggerV2->>LoggerBase: Initialize with base methods
LoggerV2->>LoggerV2: Add context with WithContext()
LoggerV2->>LoggerBase: Log Info/Debug messages
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configuration File (
|
core/log/logger.go
Outdated
type LoggerV2 interface { | ||
LoggerBase | ||
|
||
// WithV2 returns a type which can be cast to LoggerV2 with additional context provided by a set. | ||
// any is returned instead of LoggerV2 to avoid the need for log users to import the log package directly. | ||
WithV2(keyVals ...any) any | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not attached to this naming if someone can think of something better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AH! I was scratching my head yesterday about how to achieve the same thing main...julien/log-dep :D
We quite need log
to have no core
dep as well actually.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I actually don't like WithV2
in a function name if this is going to be long lived. How about WithContext
?
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
Outside diff range, codebase verification and nitpick comments (3)
log/testing.go (2)
28-30
: Update the type ofrunLogger
toLoggerV2
The variable
runLogger
intestutils/sims/runner.go
is currently declared aslog.Logger
. SinceNewTestLoggerInfo
now returnsLoggerV2
, you should update the type ofrunLogger
toLoggerV2
to ensure type consistency.
testutils/sims/runner.go
: Update the declaration ofrunLogger
toLoggerV2
.Analysis chain
LGTM! But verify the function usage in the codebase.
The change to return
LoggerV2
instead ofLogger
is approved.However, ensure that all function calls to
NewTestLoggerInfo
are correctly handled with the new return type.Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify all function calls to `NewTestLoggerInfo` match the new return type. # Test: Search for the function usage. Expect: Only occurrences of the new return type. rg --type go -A 5 $'NewTestLoggerInfo'Length of output: 1240
Script:
#!/bin/bash # Description: Verify all usages of `runLogger` in `testutils/sims/runner.go` to ensure it is handled as `LoggerV2`. # Test: Search for all occurrences of `runLogger` in the file. rg --type go 'runLogger' testutils/sims/runner.goLength of output: 253
37-39
: Type mismatch detected forlogger
intestutils/sims/runner.go
.The variable
logger
is currently of typelog.Logger
, butNewTestLoggerError
now returnsLoggerV2
. This needs to be corrected to avoid type incompatibility issues.
- Update the type of
logger
intestutils/sims/runner.go
toLoggerV2
.Analysis chain
LGTM! But verify the function usage in the codebase.
The change to return
LoggerV2
instead ofLogger
is approved.However, ensure that all function calls to
NewTestLoggerError
are correctly handled with the new return type.
Ensure
logger
intestutils/sims/runner.go
is of typeLoggerV2
.The function
NewTestLoggerError
is used intestutils/sims/runner.go
. We need to confirm that the variablelogger
is of the correct type (LoggerV2
).Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify all function calls to `NewTestLoggerError` match the new return type. # Test: Search for the function usage. Expect: Only occurrences of the new return type. rg --type go -A 5 $'NewTestLoggerError'Length of output: 1266
Script:
#!/bin/bash # Description: Verify the type of the variable `logger` in `testutils/sims/runner.go`. # Test: Search for the variable declaration and type. Expect: The type should be `LoggerV2`. rg --type go 'var logger' -A 5 testutils/sims/runner.goLength of output: 191
log/logger.go (1)
Update variable types to match the new return type
LoggerV2
The function
NewLogger
now returnsLoggerV2
instead ofLogger
. However, there are multiple instances in the codebase where the returned value is assigned to a variable of typelog.Logger
. This discrepancy needs to be addressed to ensure type compatibility.Please update the variable types to match the new return type
LoggerV2
in the following files:
testutil/sims/simulation_helpers.go
testutil/network/network.go
tools/cosmovisor/args.go
tools/cosmovisor/upgrade_test.go
tools/cosmovisor/process_test.go
tools/cosmovisor/cmd/cosmovisor/init_test.go
tests/integration/example/example_test.go
server/cmt_cmds.go
server/v2/server_test.go
server/v2/store/commands.go
server/v2/logger.go
server/v2/commands.go
server/util.go
simapp/v2/simdv2/cmd/commands.go
log/logger.go
log/writer_test.go
log/logger_test.go
client/snapshot/restore.go
client/snapshot/export.go
client/pruning/main.go
client/cmd.go
baseapp/baseapp_test.go
Analysis chain
Line range hint
77-103
:
LGTM! But verify the function usage in the codebase.The change to return
LoggerV2
instead ofLogger
is approved.However, ensure that all function calls to
NewLogger
are correctly handled with the new return type.
Let's verify if the instances of
NewLogger
are correctly handling the new return typeLoggerV2
.Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify all function calls to `NewLogger` match the new return type. # Test: Search for the function usage. Expect: Only occurrences of the new return type. rg --type go -A 5 $'NewLogger'Length of output: 10612
Script:
#!/bin/bash # Description: Verify if the returned value from `NewLogger` is used correctly as `LoggerV2`. # Test: Check the type usage of the returned value from `NewLogger` in the identified files. # List of files to check files=( "testutil/sims/simulation_helpers.go" "testutil/network/network.go" "tools/cosmovisor/args.go" "tools/cosmovisor/upgrade_test.go" "tools/cosmovisor/process_test.go" "tools/cosmovisor/cmd/cosmovisor/init_test.go" "tests/integration/example/example_test.go" "server/cmt_cmds.go" "server/v2/server_test.go" "server/v2/store/commands.go" "server/v2/logger.go" "server/v2/commands.go" "server/util.go" "simapp/v2/simdv2/cmd/commands.go" "log/logger.go" "log/writer_test.go" "log/logger_test.go" "client/snapshot/restore.go" "client/snapshot/export.go" "client/pruning/main.go" "client/cmd.go" "baseapp/baseapp_test.go" ) # Search for the usage of the returned value from `NewLogger` in each file for file in "${files[@]}"; do echo "Checking file: $file" rg --type go --context 5 'log.NewLogger' "$file" doneLength of output: 13580
Review details
Configuration used: .coderabbit.yml
Review profile: CHILL
Files selected for processing (3)
- core/log/logger.go (2 hunks)
- log/logger.go (5 hunks)
- log/testing.go (3 hunks)
Additional context used
Path-based instructions (3)
log/testing.go (1)
Pattern
**/*.go
: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.core/log/logger.go (1)
Pattern
**/*.go
: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.log/logger.go (1)
Pattern
**/*.go
: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.
Additional comments not posted (10)
log/testing.go (2)
19-21
: LGTM! But verify the function usage in the codebase.The change to return
LoggerV2
instead ofLogger
is approved.However, ensure that all function calls to
NewTestLogger
are correctly handled with the new return type.
Line range hint
41-51
:
LGTM! But verify the function usage in the codebase.The change to return
LoggerV2
instead ofLogger
is approved.However, ensure that all function calls to
newTestLogger
are correctly handled with the new return type.Verification successful
The change to return
LoggerV2
instead ofLogger
is correctly handled.The functions
NewTestLoggerInfo
andNewTestLoggerError
are used appropriately intestutils/sims/runner.go
, and theLoggerV2
type is correctly managed in these instances.
NewTestLoggerInfo
is assigned torunLogger
and used with theWith
method.NewTestLoggerError
is assigned tologger
and used with theWith
method.Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify all function calls to `newTestLogger` match the new return type. # Test: Search for the function usage. Expect: Only occurrences of the new return type. rg --type go -A 5 $'newTestLogger'Length of output: 916
Script:
#!/bin/bash # Description: Verify the usage of functions that call `newTestLogger` to ensure the return type `LoggerV2` is correctly handled. # Test: Search for the usage of functions that call `newTestLogger`. rg --type go -A 5 'NewTestLoggerDebug\(\)' rg --type go -A 5 'NewTestLoggerInfo\(\)' rg --type go -A 5 'NewTestLoggerError\(\)'Length of output: 133
Script:
#!/bin/bash # Description: Verify the usage of functions that call `newTestLogger` to ensure the return type `LoggerV2` is correctly handled. # Test: Search for the usage of functions that call `newTestLogger` with a more general pattern. rg --type go 'NewTestLogger(Debug|Info|Error)'Length of output: 547
Script:
#!/bin/bash # Description: Verify the usage of `NewTestLoggerInfo` and `NewTestLoggerError` in `testutils/sims/runner.go` to ensure the return type `LoggerV2` is correctly handled. # Test: Search for the usage of `NewTestLoggerInfo` and `NewTestLoggerError` in `testutils/sims/runner.go`. rg --type go -A 5 'NewTestLoggerInfo\(' testutils/sims/runner.go rg --type go -A 5 'NewTestLoggerError\(' testutils/sims/runner.goLength of output: 484
core/log/logger.go (3)
10-14
: LGTM!The change to embed
LoggerBase
and include theWith
method in theLogger
interface is approved.
Line range hint
16-38
:
LGTM!The
LoggerBase
interface defines basic logging functionalities and the change is approved.
40-48
: LGTM!The change to embed
LoggerBase
and include theWithV2
method in theLoggerV2
interface is approved.log/logger.go (5)
43-47
: LGTM!The change to combine the existing
Logger
and the newcorelog.LoggerV2
interfaces in theLoggerV2
type is approved.
148-151
: LGTM! But verify the function usage in the codebase.The change to return
corelog.Logger
instead ofLogger
is approved.However, ensure that all function calls to
With
are correctly handled with the new return type.
153-155
: LGTM! But verify the function usage in the codebase.The addition of the
WithV2
function is approved.However, ensure that all function calls to
WithV2
are correctly handled.Verification successful
LGTM! But verify the function usage in the codebase.
The addition of the
WithV2
function is approved. Both definitions inlog/logger.go
look correct, and the comment incore/log/logger.go
is consistent with the function's purpose.However, ensure that all function calls to
WithV2
are correctly handled.
log/logger.go
:
func (l zeroLogWrapper) WithV2(keyVals ...interface{}) any
func (l LogWrapper) WithV2(keyVals ...interface{}) any
Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify all function calls to `WithV2` match the new function. # Test: Search for the function usage. Expect: Only occurrences of the new function. rg --type go -A 5 $'WithV2'Length of output: 912
173-175
: LGTM! But verify the function usage in the codebase.The change to return
LoggerV2
instead ofLogger
is approved.However, ensure that all function calls to
NewLogWrapper
are correctly handled with the new return type.Verification successful
Verified: All instances of
NewLogWrapper
correctly handle the new return typeLoggerV2
.The change to return
LoggerV2
instead ofLogger
is correctly implemented and consistent across the codebase.
log/logger.go
: All usages ofNewLogWrapper
are correctly updated.Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify all function calls to `NewLogWrapper` match the new return type. # Test: Search for the function usage. Expect: Only occurrences of the new return type. rg --type go -A 5 $'NewLogWrapper'Length of output: 659
Script:
#!/bin/bash # Description: Verify all function calls to `NewLogWrapper` match the new return type across the entire codebase. # Test: Search for the function usage in the entire codebase. Expect: Only occurrences of the new return type. rg --type go -A 5 'NewLogWrapper'Length of output: 659
119-121
: LGTM! But verify the function usage in the codebase.The change to return
LoggerV2
instead ofLogger
is approved.However, ensure that all function calls to
NewCustomLogger
are correctly handled with the new return type.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since logger is not v1 should we break the api of v1 then move to tag v1?
cosmossdk.io/log is published as 1.x: https://pkg.go.dev/cosmossdk.io/log |
Ah whoops. Then this makes sense. Alternatively we can do a v2 pkg |
I think it would be nice to support this somehow with v1. So the most minimal version of this PR involves adding a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ack. we should remove the dep from log if possible then
Remove the dependency on core? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK. I'd argue then that the actual corelog.Logger
(with With(...) Logger
) can be moved back to log.
We can make the SDK use LoggerV2 thorough and kill all deps on core in log (started yesterday here and this is the perfect addition: main...julien/log-dep)
We can't actually remove the dependency on |
Also, change the signature of all the constructors to return |
What would be the breaking change? The log.Logger interface (currently aliased to core), is present in logger v1. Core hasn't released the Logger interface just yet. So that'd be using LoggerBase / LoggerV2 for everything in the SDK and we should still be able to pass a cosmossdk.io/log/Logger in there I think. We've added a dependency of core in logger to not directly import If we were to release log with cosmossdk.io/core as dependency, it won't work with v0.47 and v0.50 anymore. |
Wait a second if the |
Okay, I've updated this PR to remove the Constructor functions in |
log/logger.go
Outdated
type LoggerV2 interface { | ||
LoggerBase | ||
|
||
// WithContext returns a new wrapped logger with additional context provided by the key value pairs. | ||
// The returned value can be safely cast to LoggerV2. An any is returned instead of LoggerV2 | ||
// to avoid the need for log users to import the log package directly. | ||
WithContext(keyVals ...any) any | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we make these internal? it will be confusing to see which one to use
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Meaning put them in an internal package? We can just avoid declaring the interface at all and then do it in log/v2 if we want
…endency free (#21045) Co-authored-by: marbar3778 <marbar3778@yahoo.com> Co-authored-by: Julien Robert <julien@rbrt.fr> (cherry picked from commit 5c90246) # Conflicts: # runtime/v2/go.mod # schema/module_schema_test.go # server/v2/go.mod # server/v2/go.sum # server/v2/store/server.go # simapp/v2/simdv2/cmd/testnet.go
* main: feat(log): remove core dependency and update core interface to be dependency free (#21045) chore: fix some comments (#21085) feat: simulate nested messages (#20291) chore(network): remove `DefaultConfigWithAppConfigWithQueryGasLimit` (#21055) fix(runtime): remove `appv1alpha1.Config` from runtime (#21042) feat(simapp/v2): Add store server to testnet init cmd (#21076) chore(indexer/postgres): update to changes on main (#21077) feat(schema/appdata): async listener mux'ing (#20879) ci: Use large box for 052 branch sims on CI (#21067) chore(all): replace all `fmt.Errorf` without paramters with `errors.New` (#21068)
Description
In
cosmossdk.io/schema
a logger interface is defined without theWith
function because this function depends on the concreteLogger
type incore
. There is no way to define an expectedLogger
interface with theWith
method using the current design.This PR proposes a new
LoggerV2
interface with aWithV2
method that returns anany
that can be cast toLoggerV2
. With this interface, schema or other libraries could use the full logging functionality without a direct dependency oncore
orlog
(whichschema
seeks to avoid).Author Checklist
All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.
I have...
!
in the type prefix if API or client breaking changeCHANGELOG.md
Reviewers Checklist
All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.
Please see Pull Request Reviewer section in the contributing guide for more information on how to review a pull request.
I have...
Summary by CodeRabbit
New Features
LoggerV2
, enhancing flexibility and extensibility in logging functionalities.WithContext
method to improve context handling in logging.Bug Fixes
Refactor