Documentation ¶
Index ¶
- func NewSyncWriter(w io.Writer) io.Writer
- func NewTMFmtLogger(w io.Writer) kitlog.Logger
- type LazyBlockHash
- type LazySprintf
- type Logger
- func NewFilter(next Logger, options ...Option) Logger
- func NewNopLogger() Logger
- func NewTMJSONLogger(w io.Writer) Logger
- func NewTMJSONLoggerNoTS(w io.Writer) Logger
- func NewTMLogger(w io.Writer) Logger
- func NewTMLoggerWithColorFn(w io.Writer, colorFn func(keyvals ...any) term.FgBgColor) Logger
- func NewTracingLogger(next Logger) Logger
- func TestingLogger() Logger
- func TestingLoggerWithColorFn(colorFn func(keyvals ...any) term.FgBgColor) Logger
- func TestingLoggerWithOutput(w io.Writer) Logger
- type Option
- func AllowAll() Option
- func AllowDebug() Option
- func AllowDebugWith(key any, value any) Option
- func AllowError() Option
- func AllowErrorWith(key any, value any) Option
- func AllowInfo() Option
- func AllowInfoWith(key any, value any) Option
- func AllowLevel(lvl string) (Option, error)
- func AllowNone() Option
- func AllowNoneWith(key any, value any) Option
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewSyncWriter ¶
NewSyncWriter returns a new writer that is safe for concurrent use by multiple goroutines. Writes to the returned writer are passed on to w. If another write is already in progress, the calling goroutine blocks until the writer is available.
If w implements the following interface, so does the returned writer.
interface { Fd() uintptr }
func NewTMFmtLogger ¶
NewTMFmtLogger returns a logger that encodes keyvals to the Writer in CometBFT custom format. Note complex types (structs, maps, slices) formatted as "%+v".
Each log event produces no more than one call to w.Write. The passed Writer must be safe for concurrent use by multiple goroutines if the returned Logger will be used concurrently.
Types ¶
type LazyBlockHash ¶
type LazyBlockHash struct {
// contains filtered or unexported fields
}
func NewLazyBlockHash ¶
func NewLazyBlockHash(block hashable) *LazyBlockHash
NewLazyBlockHash defers block Hash until the Stringer interface is invoked. This is particularly useful for avoiding calling Sprintf when debugging is not active.
func (*LazyBlockHash) String ¶
func (l *LazyBlockHash) String() string
type LazySprintf ¶
type LazySprintf struct {
// contains filtered or unexported fields
}
func NewLazySprintf ¶
func NewLazySprintf(format string, args ...any) *LazySprintf
NewLazySprintf defers fmt.Sprintf until the Stringer interface is invoked. This is particularly useful for avoiding calling Sprintf when debugging is not active.
func (*LazySprintf) String ¶
func (l *LazySprintf) String() string
type Logger ¶
type Logger interface { Debug(msg string, keyvals ...any) Info(msg string, keyvals ...any) Error(msg string, keyvals ...any) With(keyvals ...any) Logger }
Logger is what any CometBFT library should take.
func NewFilter ¶
NewFilter wraps next and implements filtering. See the commentary on the Option functions for a detailed description of how to configure levels. If no options are provided, all leveled log events created with Debug, Info or Error helper methods are squelched.
func NewNopLogger ¶
func NewNopLogger() Logger
NewNopLogger returns a logger that doesn't do anything.
func NewTMJSONLogger ¶
NewTMJSONLogger returns a Logger that encodes keyvals to the Writer as a single JSON object. Each log event produces no more than one call to w.Write. The passed Writer must be safe for concurrent use by multiple goroutines if the returned Logger will be used concurrently.
func NewTMJSONLoggerNoTS ¶
NewTMJSONLoggerNoTS is the same as NewTMJSONLogger, but without the timestamp.
func NewTMLogger ¶
NewTMLogger returns a logger that encodes msg and keyvals to the Writer using go-kit's log as an underlying logger and our custom formatter. Note that underlying logger could be swapped with something else.
func NewTMLoggerWithColorFn ¶
NewTMLoggerWithColorFn allows you to provide your own color function. See NewTMLogger for documentation.
func NewTracingLogger ¶
NewTracingLogger enables tracing by wrapping all errors (if they implement stackTracer interface) in tracedError.
All errors returned by https://github.com/pkg/errors implement stackTracer interface.
For debugging purposes only as it doubles the amount of allocations.
func TestingLogger ¶
func TestingLogger() Logger
TestingLogger returns a TMLogger which writes to STDOUT if testing being run with the verbose (-v) flag, NopLogger otherwise.
Note that the call to TestingLogger() must be made inside a test-2 (not in the init func) because verbose flag only set at the time of testing.
func TestingLoggerWithColorFn ¶
TestingLoggerWithColorFn allow you to provide your own color function. See TestingLogger for documentation.
func TestingLoggerWithOutput ¶
TestingLoggerWOutput returns a TMLogger which writes to (w io.Writer) if testing being run with the verbose (-v) flag, NopLogger otherwise.
Note that the call to TestingLoggerWithOutput(w io.Writer) must be made inside a test-2 (not in the init func) because verbose flag only set at the time of testing.
type Option ¶
type Option func(*filter)
Option sets a parameter for the filter.
func AllowDebug ¶
func AllowDebug() Option
AllowDebug allows error, info and debug level log events to pass.
func AllowDebugWith ¶
AllowDebugWith allows error, info and debug level log events to pass for a specific key value pair.
func AllowErrorWith ¶
AllowErrorWith allows only error level log events to pass for a specific key value pair.
func AllowInfoWith ¶
AllowInfoWith allows error and info level log events to pass for a specific key value pair.
func AllowLevel ¶
AllowLevel returns an option for the given level or error if no option exist for such level.
func AllowNoneWith ¶
AllowNoneWith allows no leveled log events to pass for a specific key value pair.