log

package
v0.0.0-...-1abf0d1 Latest Latest
Warning

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

Go to latest
Published: May 19, 2023 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// LogFormatPlain defines a logging format used for human-readable text-based
	// logging that is not structured. Typically, this format is used for development
	// and testing purposes.
	LogFormatPlain string = "plain"

	// LogFormatText defines a logging format used for human-readable text-based
	// logging that is not structured. Typically, this format is used for development
	// and testing purposes.
	LogFormatText string = "text"

	// LogFormatJSON defines a logging format for structured JSON-based logging
	// that is typically used in production environments, which can be sent to
	// logging facilities that support complex log parsing and querying.
	LogFormatJSON string = "json"

	// Supported loging levels
	LogLevelDebug = "debug"
	LogLevelInfo  = "info"
	LogLevelWarn  = "warn"
	LogLevelError = "error"
)

Variables

This section is empty.

Functions

func NewSyncWriter

func NewSyncWriter(w io.Writer) io.Writer

func NewTMFmtLogger

func NewTMFmtLogger(w io.Writer) kitlog.Logger

NewTMFmtLogger returns a logger that encodes keyvals to the Writer in Tendermint 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 OverrideWithNewLogger

func OverrideWithNewLogger(logger Logger, format, level string) error

OverrideWithNewLogger replaces an existing logger's internal with a new logger, and makes it possible to reconfigure an existing logger that has already been propagated to callers.

Types

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 defines a generic logging interface compatible with Tendermint.

func NewDefaultLogger

func NewDefaultLogger(format, level string) (Logger, error)

NewDefaultLogger returns a default logger that can be used within Tendermint and that fulfills the Logger interface. The underlying logging provider is a zerolog logger that supports typical log levels along with JSON and plain/text log formats.

Since zerolog supports typed structured logging and it is difficult to reflect that in a generic interface, all logging methods accept a series of key/value pair tuples, where the key must be a string.

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

func NewTMJSONLogger

func NewTMJSONLogger(w io.Writer) Logger

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

func NewTMJSONLoggerNoTS(w io.Writer) Logger

NewTMJSONLoggerNoTS is the same as NewTMJSONLogger, but without the timestamp.

func NewTMLogger

func NewTMLogger(w io.Writer) Logger

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

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

NewTMLoggerWithColorFn allows you to provide your own color function. See NewTMLogger for documentation.

func NewTestingLogger

func NewTestingLogger(t testing.TB) Logger

NewTestingLogger converts a testing.T into a logging interface to make test failures and verbose provide better feedback associated with test failures. This logging instance is safe for use from multiple threads, but in general you should create one of these loggers ONCE for each *testing.T instance that you interact with.

By default it collects only ERROR messages, or DEBUG messages in verbose mode, and relies on the underlying behavior of testing.T.Log()

Users should be careful to ensure that no calls to this logger are made in goroutines that are running after (which, by the rules of testing.TB will panic.)

func NewTestingLoggerWithLevel

func NewTestingLoggerWithLevel(t testing.TB, level string) Logger

NewTestingLoggerWithLevel creates a testing logger instance at a specific level that wraps the behavior of testing.T.Log().

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 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 (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 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 (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.

Jump to

Keyboard shortcuts

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