Documentation ¶
Index ¶
Constants ¶
const ModuleKey = "module"
ModuleKey defines a module logging key.
Variables ¶
var ContextKey struct{}
ContextKey is used to store the logger in the context.
Functions ¶
func NewFilterWriter ¶ added in v1.0.0
func NewFilterWriter(parent io.Writer, filter FilterFunc) io.Writer
NewFilterWriter returns a writer that filters out all key/value pairs that do not match the filter. If the filter is nil, the writer will pass all events through. The filter function is called with the module and level of the event.
Types ¶
type Config ¶ added in v1.0.0
type Config struct { Level zerolog.Level Filter FilterFunc OutputJSON bool Color bool StackTrace bool TimeFormat string Hooks []zerolog.Hook }
Config defines configuration for the logger.
type FilterFunc ¶
FilterFunc is a function that returns true if the log level is filtered for the given key When the filter returns true, the log entry is discarded.
func ParseLogLevel ¶
func ParseLogLevel(levelStr string) (FilterFunc, 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")
This function attempts to keep the same behavior as the CometBFT ParseLogLevel However the level `none` is replaced by `disabled`.
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) // Warn takes a message and a set of key/value pairs and logs with level WARN. // The key of the tuple must be a string. Warn(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 NewCustomLogger ¶
NewCustomLogger returns a new logger with the given zerolog logger.
func NewLogger ¶
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 NewTestLogger ¶
NewTestLogger returns a logger that calls t.Log to write entries.
The returned logger emits messages at any level. For active debugging of a test with verbose logs, the NewTestLoggerInfo and NewTestLoggerError functions only emit messages at or above the corresponding log levels.
If the logs may help debug a test failure, you may want to use NewTestLogger(t) in your test. Otherwise, use NewNopLogger().
func NewTestLoggerError ¶ added in v1.0.0
NewTestLoggerError returns a test logger that filters out messages below Error level.
This is primarily helpful during active debugging of a test with verbose logs.
type Option ¶ added in v1.0.0
type Option func(*Config)
func ColorOption ¶ added in v1.1.0
ColorOption add option to enable/disable coloring of the logs when console writer is in use
func FilterOption ¶ added in v1.0.0
func FilterOption(filter FilterFunc) Option
FilterOption sets the filter for the Logger.
func HooksOption ¶ added in v1.3.0
HooksOption append hooks to the Logger hooks
func LevelOption ¶ added in v1.0.0
LevelOption sets the level for the Logger. Messages with a lower level will be discarded.
func OutputJSONOption ¶ added in v1.0.0
func OutputJSONOption() Option
OutputJSONOption sets the output of the logger to JSON. By default, the logger outputs to a human-readable format.
func TimeFormatOption ¶ added in v1.1.0
TimeFormatOption configures timestamp format of the logger timestamps disabled if empty. it is responsibility of the caller to provider correct values Supported formats:
- time.Layout
- time.ANSIC
- time.UnixDate
- time.RubyDate
- time.RFC822
- time.RFC822Z
- time.RFC850
- time.RFC1123
- time.RFC1123Z
- time.RFC3339
- time.RFC3339Nano
- time.Kitchen
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.