-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
747c29e
commit fba6762
Showing
61 changed files
with
171 additions
and
208 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
# Log | ||
|
||
The `cosmossdk.io/log` provides simple logging implementations for the Cosmos SDK and Cosmos SDK modules. | ||
The `cosmossdk.io/log` provides a zerolog logging implementation for the Cosmos SDK and Cosmos SDK modules. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,17 @@ | ||
github.com/cometbft/cometbft v0.37.0-alpha.3 h1:74F+cMr4pd1a2lFn/h4TxXmO8VWi3A2dxyoMcjlMWuQ= | ||
github.com/cometbft/cometbft v0.37.0-alpha.3/go.mod h1:dUGbIGYoLM11xUruTTJY4Xp9FHh6Nfu3Nots8/+UNSo= | ||
github.com/coreos/go-systemd/v22 v22.3.3-0.20220203105225-a9a7ef127534/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc= | ||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= | ||
github.com/go-kit/log v0.2.1 h1:MRVx0/zhvdseW+Gza6N9rVzU/IVzaeE1SFI4raAhmBU= | ||
github.com/go-kit/log v0.2.1/go.mod h1:NwTd00d/i8cPZ3xOwwiv2PO5MOcx78fFErGNcVmBjv0= | ||
github.com/go-logfmt/logfmt v0.5.1 h1:otpy5pqBCBZ1ng9RQ0dPu4PN7ba75Y/aA+UpowDyNVA= | ||
github.com/go-logfmt/logfmt v0.5.1/go.mod h1:WYhtIu8zTZfxdn5+rREduYbwxfcBr/Vr6KEVveWlfTs= | ||
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= | ||
github.com/mattn/go-colorable v0.1.12/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4= | ||
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= | ||
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg= | ||
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94= | ||
github.com/mattn/go-isatty v0.0.16 h1:bq3VjFmv/sOjHtdEhmkEV4x1AJtvUvOJ2PFAZ5+peKQ= | ||
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= | ||
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= | ||
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= | ||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= | ||
github.com/rs/xid v1.4.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg= | ||
github.com/rs/zerolog v1.29.0 h1:Zes4hju04hjbvkVkOhdl2HpZa+0PmVwigmo8XoORE5w= | ||
github.com/rs/zerolog v1.29.0/go.mod h1:NILgTygv/Uej1ra5XxGf82ZFSLk58MFGAUS2o6usyD0= | ||
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk= | ||
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= | ||
golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= | ||
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= | ||
golang.org/x/sys v0.5.0 h1:MUK/U/4lj1t1oPg0HfuXDN/Z1wv31ZJ/YcPiGccS4DU= | ||
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= | ||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,65 @@ | ||
package log | ||
|
||
import cmtlog "github.com/cometbft/cometbft/libs/log" | ||
import ( | ||
"os" | ||
"time" | ||
|
||
"github.com/rs/zerolog" | ||
) | ||
|
||
// Defines commons keys for logging | ||
const ModuleKey = "module" | ||
|
||
// ContextKey is used to store the logger in the context | ||
var ContextKey struct{} | ||
|
||
// 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{}) | ||
Info(msg string, keyVals ...interface{}) | ||
Error(msg string, keyVals ...interface{}) | ||
Debug(msg string, keyVals ...interface{}) | ||
With(keyVals ...interface{}) Logger | ||
} | ||
|
||
type ZeroLogWrapper struct { | ||
zerolog.Logger | ||
} | ||
|
||
func NewNopLogger() Logger { | ||
logger := zerolog.Nop() | ||
return &ZeroLogWrapper{logger} | ||
} | ||
|
||
func NewLogger() Logger { | ||
output := zerolog.ConsoleWriter{Out: os.Stdout, TimeFormat: time.Kitchen} | ||
logger := zerolog.New(output).With().Timestamp().Logger() | ||
return &ZeroLogWrapper{logger} | ||
} | ||
|
||
func NewLoggerWithKV(key, value string) Logger { | ||
output := zerolog.ConsoleWriter{Out: os.Stdout, TimeFormat: time.Kitchen} | ||
logger := zerolog.New(output).With().Str(key, value).Timestamp().Logger() | ||
return &ZeroLogWrapper{logger} | ||
} | ||
|
||
// Info takes a message and a set of key/value pairs and logs with level INFO. | ||
// The key of the tuple must be a string. | ||
func (l ZeroLogWrapper) Info(msg string, keyVals ...interface{}) { | ||
l.Logger.Info().Fields(keyVals).Msg(msg) | ||
} | ||
|
||
// Error takes a message and a set of key/value pairs and logs with level DEBUG. | ||
// The key of the tuple must be a string. | ||
func (l ZeroLogWrapper) Error(msg string, keyVals ...interface{}) { | ||
l.Logger.Error().Fields(keyVals).Msg(msg) | ||
} | ||
|
||
// Debug takes a message and a set of key/value pairs and logs with level ERR. | ||
// The key of the tuple must be a string. | ||
func (l ZeroLogWrapper) Debug(msg string, keyVals ...interface{}) { | ||
l.Logger.Debug().Fields(keyVals).Msg(msg) | ||
} | ||
|
||
With(keyvals ...interface{}) cmtlog.Logger | ||
// With returns a new wrapped logger with additional context provided by a set | ||
func (l ZeroLogWrapper) With(keyVals ...interface{}) Logger { | ||
return ZeroLogWrapper{l.Logger.With().Fields(keyVals).Logger()} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package server | ||
|
||
import ( | ||
"cosmossdk.io/log" | ||
cmtlog "github.com/cometbft/cometbft/libs/log" | ||
) | ||
|
||
var _ cmtlog.Logger = (*CometZerologWrapper)(nil) | ||
|
||
// CometZerologWrapper provides a wrapper around a zerolog.Logger instance. | ||
// It implements CometBFT's Logger interface. | ||
type CometZerologWrapper struct { | ||
log.ZeroLogWrapper | ||
} | ||
|
||
// With returns a new wrapped logger with additional context provided by a set | ||
// of key/value tuples. The number of tuples must be even and the key of the | ||
// tuple must be a string. | ||
func (cmt CometZerologWrapper) With(keyVals ...interface{}) cmtlog.Logger { | ||
return cmt.With(keyVals...) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.