refactor: add logger package (#14872)

Co-authored-by: Julien Robert <julien@rbrt.fr>
This commit is contained in:
Marko 2023-02-02 00:42:15 +01:00 committed by GitHub
parent e167643d6e
commit 6b256ce7c0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 109 additions and 6 deletions

View File

@ -171,4 +171,11 @@ updates:
interval: weekly
labels:
- "A:automerge"
- dependencies
- dependencies
- package-ecosystem: gomod
directory: "log"
schedule:
interval: weekly
labels:
- "A:automerge"
- dependencies

View File

@ -75,3 +75,5 @@
- store/**/*
"C:orm":
- orm/**/*
"C:log":
- log/*

View File

@ -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} ###
#############################
@ -796,4 +824,4 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
with:
projectBaseDir: x/upgrade/
projectBaseDir: x/upgrade/

View File

@ -8,6 +8,7 @@ use (
./core
./depinject
./errors
./log
./math
./orm
./simapp

32
log/CHANGELOG.md Normal file
View File

@ -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
log/go.mod Normal file
View File

@ -0,0 +1,3 @@
module github.com/cosmos/cosmos-sdk/log
go 1.19

View File

@ -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
log/noop_logger.go Normal file
View File

@ -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
}

View File

@ -0,0 +1,14 @@
sonar.projectKey=cosmos-sdk-log
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

View File

@ -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) {