forked from cosmos/cosmos-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor Logging using Zerolog (cosmos#8072)
* init commit * server: use flags * server: godoc++ * updates * baseapp: update logging * logging updates * x/bank: update logging * logging updates * lint++ * logging updates * logging updates * logging updates * logging updates * cl++
- Loading branch information
1 parent
183593f
commit 5291a8f
Showing
32 changed files
with
229 additions
and
112 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
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,55 @@ | ||
package server | ||
|
||
import ( | ||
"github.com/rs/zerolog" | ||
tmlog "github.com/tendermint/tendermint/libs/log" | ||
) | ||
|
||
var _ tmlog.Logger = (*ZeroLogWrapper)(nil) | ||
|
||
// ZeroLogWrapper provides a wrapper around a zerolog.Logger instance. It implements | ||
// Tendermint's Logger interface. | ||
type ZeroLogWrapper struct { | ||
zerolog.Logger | ||
} | ||
|
||
// Info implements Tendermint's Logger interface and logs with level INFO. A set | ||
// of key/value tuples may be provided to add context to the log. The number of | ||
// tuples must be even and the key of the tuple must be a string. | ||
func (z ZeroLogWrapper) Info(msg string, keyVals ...interface{}) { | ||
z.Logger.Info().Fields(getLogFields(keyVals...)).Msg(msg) | ||
} | ||
|
||
// Error implements Tendermint's Logger interface and logs with level ERR. A set | ||
// of key/value tuples may be provided to add context to the log. The number of | ||
// tuples must be even and the key of the tuple must be a string. | ||
func (z ZeroLogWrapper) Error(msg string, keyVals ...interface{}) { | ||
z.Logger.Error().Fields(getLogFields(keyVals...)).Msg(msg) | ||
} | ||
|
||
// Debug implements Tendermint's Logger interface and logs with level DEBUG. A set | ||
// of key/value tuples may be provided to add context to the log. The number of | ||
// tuples must be even and the key of the tuple must be a string. | ||
func (z ZeroLogWrapper) Debug(msg string, keyVals ...interface{}) { | ||
z.Logger.Debug().Fields(getLogFields(keyVals...)).Msg(msg) | ||
} | ||
|
||
// 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 (z ZeroLogWrapper) With(keyVals ...interface{}) tmlog.Logger { | ||
return ZeroLogWrapper{z.Logger.With().Fields(getLogFields(keyVals...)).Logger()} | ||
} | ||
|
||
func getLogFields(keyVals ...interface{}) map[string]interface{} { | ||
if len(keyVals)%2 != 0 { | ||
return nil | ||
} | ||
|
||
fields := make(map[string]interface{}) | ||
for i := 0; i < len(keyVals); i += 2 { | ||
fields[keyVals[i].(string)] = keyVals[i+1] | ||
} | ||
|
||
return fields | ||
} |
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.