log

package
v1.1.5 Latest Latest
Warning

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

Go to latest
Published: Jun 18, 2024 License: Apache-2.0 Imports: 18 Imported by: 67

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewOCFmtLogger

func NewOCFmtLogger(w io.Writer) kitlog.Logger

NewOCFmtLogger returns a logger that encodes keyvals to the Writer in Ostracon 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.

func NewSyncWriter

func NewSyncWriter(w io.Writer) io.Writer

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
}

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 ...interface{}) *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 ...interface{})
	Info(msg string, keyvals ...interface{})
	Error(msg string, keyvals ...interface{})

	With(keyvals ...interface{}) Logger
}

Logger is what any Ostracon library should take.

func NewFilter

func NewFilter(next Logger, options ...Option) Logger

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 NewOCJSONLogger

func NewOCJSONLogger(w io.Writer) Logger

NewOCJSONLogger 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 NewOCJSONLoggerNoTS

func NewOCJSONLoggerNoTS(w io.Writer) Logger

NewOCJSONLoggerNoTS is the same as NewOCJSONLogger, but without the timestamp.

func NewOCLogger

func NewOCLogger(w io.Writer) Logger

NewOCLogger 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 NewOCLoggerWithColorFn

func NewOCLoggerWithColorFn(w io.Writer, colorFn func(keyvals ...interface{}) term.FgBgColor) Logger

NewOCLoggerWithColorFn allows you to provide your own color function. See NewOCLogger for documentation.

func NewTracingLogger

func NewTracingLogger(next Logger) Logger

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 NewZeroLogLogger

func NewZeroLogLogger(cfg ZeroLogConfig, consoleWriter io.Writer) (Logger, error)

func ParseLogLevel

func ParseLogLevel(lvl string, logger Logger, defaultLogLevelValue string) (Logger, error)

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

Example:

ParseLogLevel("consensus:debug,mempool:debug,*:error", NewOCLogger(os.Stdout), "info")

func TestingLogger

func TestingLogger() Logger

TestingLogger returns a OCLogger 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 (not in the init func) because verbose flag only set at the time of testing.

func TestingLoggerWithColorFn

func TestingLoggerWithColorFn(colorFn func(keyvals ...interface{}) term.FgBgColor) Logger

TestingLoggerWithColorFn allow you to provide your own color function. See TestingLogger for documentation.

func TestingLoggerWithOutput

func TestingLoggerWithOutput(w io.Writer) Logger

TestingLoggerWOutput returns a OCLogger 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 (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 AllowAll

func AllowAll() Option

AllowAll is an alias for AllowDebug.

func AllowDebug

func AllowDebug() Option

AllowDebug allows error, info and debug level log events to pass.

func AllowDebugWith

func AllowDebugWith(key interface{}, value interface{}) Option

AllowDebugWith allows error, info and debug level log events to pass for a specific key value pair.

func AllowError

func AllowError() Option

AllowError allows only error level log events to pass.

func AllowErrorWith

func AllowErrorWith(key interface{}, value interface{}) Option

AllowErrorWith allows only error level log events to pass for a specific key value pair.

func AllowInfo

func AllowInfo() Option

AllowInfo allows error and info level log events to pass.

func AllowInfoWith

func AllowInfoWith(key interface{}, value interface{}) Option

AllowInfoWith allows error and info level log events to pass for a specific key value pair.

func AllowLevel

func AllowLevel(lvl string) (Option, error)

AllowLevel returns an option for the given level or error if no option exist for such level.

func AllowNone

func AllowNone() Option

AllowNone allows no leveled log events to pass.

func AllowNoneWith

func AllowNoneWith(key interface{}, value interface{}) Option

AllowNoneWith allows no leveled log events to pass for a specific key value pair.

type ZeroLogConfig

type ZeroLogConfig struct {
	IsLogPlain bool
	LogLevel   string

	LogPath       string
	LogMaxAge     int
	LogMaxSize    int
	LogMaxBackups int
}

func NewZeroLogConfig

func NewZeroLogConfig(isLogPlain bool, logLevel string, logPath string, logMaxAge int, logMaxSize int, logMaxBackups int) ZeroLogConfig

type ZeroLogWrapper

type ZeroLogWrapper struct {
	zerolog.Logger
}

ZeroLogWrapper provides a wrapper around a zerolog.Logger instance. It implements Tendermint's Logger interface.

func (ZeroLogWrapper) Debug

func (z ZeroLogWrapper) Debug(msg string, keyVals ...interface{})

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 (ZeroLogWrapper) Error

func (z ZeroLogWrapper) Error(msg string, keyVals ...interface{})

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 (ZeroLogWrapper) Info

func (z ZeroLogWrapper) Info(msg string, keyVals ...interface{})

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 (ZeroLogWrapper) With

func (z ZeroLogWrapper) With(keyVals ...interface{}) Logger

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.

Jump to

Keyboard shortcuts

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