log

package module
v0.0.0-...-095f669 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 7, 2023 License: Apache-2.0 Imports: 3 Imported by: 17

README

Log

The github.com/verzth/cosmos-sdk/log provides a zerolog logging implementation for the Cosmos SDK and Cosmos SDK modules.

Documentation

Index

Constants

View Source
const ModuleKey = "module"

Defines commons keys for logging

Variables

View Source
var ContextKey struct{}

ContextKey is used to store the logger in the context

Functions

func ParseLogLevel

func ParseLogLevel(lvl string, defaultLogLevelValue string) (func(key, level string) bool, error)

ParseLogLevel parses complex log level A comma-separated list of module:level pairs with an optional *:level pair (* means all other modules).

Example: ParseLogLevel("consensus:debug,mempool:debug,*:error", "info")

Types

type Logger

type Logger interface {
	// 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.
	Info(msg string, keyVals ...any)

	// Error takes a message and a set of key/value pairs and logs with level ERR.
	// The key of the tuple must be a string.
	Error(msg string, keyVals ...any)

	// Debug takes a message and a set of key/value pairs and logs with level DEBUG.
	// The key of the tuple must be a string.
	Debug(msg string, keyVals ...any)

	// With returns a new wrapped logger with additional context provided by a set
	With(keyVals ...any) Logger

	// Impl returns the underlying logger implementation
	// It is used to access the full functionalities of the underlying logger
	// Advanced users can type cast the returned value to the actual logger
	Impl() any
}

Logger is the Cosmos SDK logger interface It maintains as much backward compatibility with the CometBFT logger as possible All functionalities of the logger are available through the Impl() method

func FilterKeys

func FilterKeys(logger Logger, filter func(key, level string) bool) Logger

FilterKeys returns a new logger that filters out all key/value pairs that do not match the filter. This functions assumes that the logger is a zerolog.Logger, which is the case for the logger returned by log.NewLogger() NOTE: filtering has a performance impact on the logger

func NewCustomLogger

func NewCustomLogger(logger zerolog.Logger) Logger

NewCustomLogger returns a new logger with the given zerolog logger.

func NewLogger

func NewLogger(dst io.Writer) Logger

NewLogger returns a new logger that writes to the given destination.

Typical usage from a main function is:

logger := log.NewLogger(os.Stderr)

Stderr is the typical destination for logs, so that any output from your application can still be piped to other processes.

func NewLoggerWithKV

func NewLoggerWithKV(dst io.Writer, key, value string) Logger

NewLoggerWithKV is shorthand for NewLogger(dst).With(key, value).

func NewNopLogger

func NewNopLogger() Logger

NewNopLogger returns a new logger that does nothing.

func NewTestLogger

func NewTestLogger(t TestingT) Logger

NewTestLogger returns a logger that calls t.Log to write entries.

If the logs may help debug a test failure, you may want to use NewTestLogger(t) in your test. Otherwise, use NewNopLogger().

type TestingT

type TestingT zerolog.TestingLog

TestingT is the interface required for logging in tests. It is a subset of testing.T to avoid a direct dependency on the testing package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL