Skip to content
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

refactor: add logger package #14872

Merged
merged 9 commits into from
Feb 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -171,4 +171,11 @@ updates:
interval: weekly
labels:
- "A:automerge"
- dependencies
- dependencies
- package-ecosystem: gomod
directory: "log"
schedule:
interval: weekly
labels:
- "A:automerge"
- dependencies
2 changes: 2 additions & 0 deletions .github/pr_labeler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,5 @@
- store/**/*
"C:orm":
- orm/**/*
"C:log":
- log/*
30 changes: 29 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,34 @@ jobs:
with:
projectBaseDir: store/

test-log:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version: 1.19.4
- uses: technote-space/get-diff-action@v6.1.2
id: git_diff
with:
PATTERNS: |
log/*.go
log/go.mod
log/go.sum
- name: tests
if: env.GIT_DIFF
run: |
cd log
go test -mod=readonly -timeout 30m -coverprofile=coverage.out -covermode=atomic -tags='norace ledger test_ledger_mock rocksdb_build' ./...
- name: sonarcloud
if: ${{ env.GIT_DIFF && !github.event.pull_request.draft }}
uses: SonarSource/sonarcloud-github-action@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
with:
projectBaseDir: log/

#############################
### Cosmos SDK x/{module} ###
#############################
Expand Down Expand Up @@ -796,4 +824,4 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
with:
projectBaseDir: x/upgrade/
projectBaseDir: x/upgrade/
1 change: 1 addition & 0 deletions go.work.example
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use (
./core
./depinject
./errors
./log
./math
./orm
./simapp
Expand Down
32 changes: 32 additions & 0 deletions log/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<!--
Guiding Principles:

Changelogs are for humans, not machines.
There should be an entry for every single version.
The same types of changes should be grouped.
Versions and sections should be linkable.
The latest version comes first.
The release date of each version is displayed.
Mention whether you follow Semantic Versioning.

Usage:

Change log entries are to be added to the Unreleased section under the
appropriate stanza (see below). Each entry should ideally include a tag and
the Github issue reference in the following format:

* (<tag>) [#<issue-number>] Changelog message.

Types of changes (Stanzas):

"Features" for new features.
"Improvements" for changes in existing functionality.
"Deprecated" for soon-to-be removed features.
"Bug Fixes" for any bug fixes.
"API Breaking" for breaking exported APIs used by developers building on SDK.
Ref: https://keepachangelog.com/en/1.0.0/
-->

# Changelog

## [Unreleased]
3 changes: 3 additions & 0 deletions log/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module github.com/cosmos/cosmos-sdk/log
Copy link
Member

@julienrbrt julienrbrt Feb 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that it is a small PR, could you add all the tooling too?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will do

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I got it all

Copy link
Member

@julienrbrt julienrbrt Feb 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just one typo, and could you add it to dependabot?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we make it cosmossdk.io/log? Why not just have this interface in core? I think there should be a core logging service

Copy link
Member

@julienrbrt julienrbrt Feb 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought core should not be containing any implementation.
If you had an interface in core and the implementation in logger that's a bit weird. Imo better to keep close the interface from its implementation for small packages like that.

Agrees that a vanity url is better however.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think a no-op implementation in core is fine. That's all this has right? I don't have a strong preference on whether it goes in core, but I do think modules will want a logging service so that should probably go in core right?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, but maybe in that log package we can add a function for these logger too, so we don't duplicate other loggers:

Copy link
Member

@aaronc aaronc Feb 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, that probably shouldn't be in core. So if we can have a simple interface with zero dependencies, the same interface can exist in core and log. Log can provide some implementations like zerolog and comet. And core can have the same interface for the service but no implementations. The main thing I think is getting rid of the dependency on comet as I mentioned here #14904 (comment)


go 1.19
6 changes: 3 additions & 3 deletions core/log/logger.go → log/logger.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package log

// Service is the interface that wraps the basic logging methods.
type Service interface {
// Logger is the interface that wraps the basic logging methods.
type Logger interface {
Debug(msg string, keyvals ...interface{})
Info(msg string, keyvals ...interface{})
Error(msg string, keyvals ...interface{})

With(keyvals ...interface{}) Service
With(keyvals ...interface{}) Logger
}
17 changes: 17 additions & 0 deletions log/noop_logger.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package log

var _ Logger = &NoOp{}

type NoOp struct{}

func NewNoOpLogger() *NoOp {
return &NoOp{}
}

func (l NoOp) Debug(msg string, keyvals ...interface{}) {}
func (l NoOp) Info(msg string, keyvals ...interface{}) {}
func (l NoOp) Error(msg string, keyvals ...interface{}) {}

func (l NoOp) With(i ...interface{}) Logger {
return l
}
14 changes: 14 additions & 0 deletions log/sonar-project.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
sonar.projectKey=cosmos-sdk-log
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sonar.organization=cosmos

sonar.projectName=Cosmos SDK - Log
sonar.project.monorepo.enabled=true

sonar.sources=.
sonar.exclusions=**/*_test.go
sonar.tests=.
sonar.test.inclusions=**/*_test.go
sonar.go.coverage.reportPaths=coverage.out

sonar.sourceEncoding=UTF-8
sonar.scm.provider=git
1 change: 0 additions & 1 deletion types/module/module_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,6 @@ func TestCoreAPIManager_BeginBlock(t *testing.T) {
mockAppModule1.EXPECT().BeginBlock(gomock.Any()).Times(1).Return(errors.New("some error"))
_, err = mm.BeginBlock(sdk.Context{}, req)
require.EqualError(t, err, "some error")

}

func TestCoreAPIManager_EndBlock(t *testing.T) {
Expand Down