Documentation
¶
Index ¶
Constants ¶
const ModuleKey = "module"
ModuleKey defines a module logging key.
Variables ¶
var ContextKey contextKey
ContextKey is used to store the logger in the context.
Functions ¶
func NewFilterWriter ¶
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.
func WithJSONMarshal ¶
WithJSONMarshal configures zerolog global json encoding.
Types ¶
type Config ¶
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 extends github.com/SkyVeX-SVX/skyvex-sdk/core/log.Logger to return a child logger. Use github.com/SkyVeX-SVX/skyvex-sdk/core/log.Logger instead in modules.
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. The returned value can be safely cast to github.com/SkyVeX-SVX/skyvex-sdk/core/log.Logger.
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 ¶
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.
func NewTestLoggerInfo ¶
NewTestLoggerInfo returns a test logger that filters out messages below info level.
This is primarily helpful during active debugging of a test with verbose logs.
type Option ¶
type Option func(*Config)
func ColorOption ¶
ColorOption add option to enable/disable coloring of the logs when console writer is in use
func FilterOption ¶
func FilterOption(filter FilterFunc) Option
FilterOption sets the filter for the Logger.
func HooksOption ¶
HooksOption append hooks to the Logger hooks
func LevelOption ¶
LevelOption sets the level for the Logger. Messages with a lower level will be discarded.
func OutputJSONOption ¶
func OutputJSONOption() Option
OutputJSONOption sets the output of the logger to JSON. By default, the logger outputs to a human-readable format.
func TimeFormatOption ¶
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
func TraceOption ¶
TraceOption add option to enable/disable print of stacktrace on error log
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.
Directories
¶
Path | Synopsis |
---|---|
Package slog contains a Logger type that satisfies github.com/SkyVeX-SVX/skyvex-sdk/log.Logger, backed by a standard library *log/slog.Logger.
|
Package slog contains a Logger type that satisfies github.com/SkyVeX-SVX/skyvex-sdk/log.Logger, backed by a standard library *log/slog.Logger. |