Documentation ¶
Index ¶
- Constants
- func CtxWithLogger(ctx context.Context, logger Logger) context.Context
- func NewFormatter(format string, w io.Writer) (io.Writer, error)
- func OverrideWithNewLogger(logger Logger, format, level, additionalLogFilePath string) error
- type Logger
- type TestingLogger
- func (tw *TestingLogger) AssertContains(s string)
- func (tw *TestingLogger) AssertMatch(re *regexp.Regexp)
- func (tw *TestingLogger) AssertionsPassed() bool
- func (l *TestingLogger) Close() (err error)
- func (l TestingLogger) Debug(msg string, keyVals ...interface{})
- func (l TestingLogger) Error(msg string, keyVals ...interface{})
- func (l TestingLogger) Info(msg string, keyVals ...interface{})
- func (l TestingLogger) Trace(msg string, keyVals ...interface{})
- func (l TestingLogger) Warn(msg string, keyVals ...interface{})
- func (l TestingLogger) With(keyVals ...interface{}) Logger
- func (tw *TestingLogger) WithTimestamp() *TestingLogger
- func (tw *TestingLogger) Write(in []byte) (int, error)
Constants ¶
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 LogLevelTrace = "trace" LogLevelDebug = "debug" LogLevelInfo = "info" LogLevelWarn = "warn" LogLevelError = "error" )
Variables ¶
This section is empty.
Functions ¶
func CtxWithLogger ¶
CtxWithLogger adds a logger instance to a context
func NewFormatter ¶
NewFormatter creates a new formatter for the given format. If the format is empty or unsupported then returns error.
func OverrideWithNewLogger ¶
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 { io.Closer // Trace events are logged from the primary path of execution (eg. when everything goes well) Trace(msg string, keyVals ...interface{}) // Debug events are used in non-primary path to provide fine-grained information useful for debugging Debug(msg string, keyVals ...interface{}) // Info events provide general, business-level information about what's happening inside the application, to // let the user know what the application is doing Info(msg string, keyVals ...interface{}) // Warn events are used when something unexpected happened, but the application can recover/continue Warn(msg string, keyVals ...interface{}) // Error events are used when something unexpected happened and the application cannot recover, or the // issue is serious and the user needs to take action Error(msg string, keyVals ...interface{}) With(keyVals ...interface{}) Logger }
Logger defines a generic logging interface compatible with Tendermint.
func FromCtxOrNop ¶
FromCtxOrNop gets a logger instance from a context returns Nop logger if logget didn't add
func NewDefaultLogger ¶
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 NewMultiLogger ¶ added in v0.13.2
NewMultiLogger creates a new logger that writes to os.Stderr and an additional log file if provided. It takes in three parameters: format, level, and additionalLogPath. The format parameter specifies the format of the log message. The level parameter specifies the minimum log level to write. The additionalLogPath parameter specifies the path to the additional log file. If additionalLogPath is not empty, the logger writes to both os.Stderr and the additional log file. The function returns a Logger interface and an error if any.
See NewDefaultLogger for more details.
func NewNopLogger ¶
func NewNopLogger() Logger
type TestingLogger ¶
type TestingLogger struct {
// contains filtered or unexported fields
}
func NewTestingLogger ¶
func NewTestingLogger(t testing.TB) *TestingLogger
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) *TestingLogger
NewTestingLoggerWithLevel creates a testing logger instance at a specific level that wraps the behavior of testing.T.Log().
func (*TestingLogger) AssertContains ¶ added in v1.0.0
func (tw *TestingLogger) AssertContains(s string)
AssertContains defines assertions to check for each subsequent log item. It must be called before the log is generated. Assertion will pass if at least one log contains `s`.
Note that assertions are only executed on logs matching defined log level. Use NewTestingLoggerWithLevel(t, zerolog.LevelDebugValue) to control this.
func (*TestingLogger) AssertMatch ¶
func (tw *TestingLogger) AssertMatch(re *regexp.Regexp)
AssertMatch definies assertions to check for each subsequent log item. It must be called before the log is generated. Assertion will pass if at least one log matches regexp `re`.
Note that assertions are only executed on logs matching defined log level. Use NewTestingLoggerWithLevel(t, zerolog.LevelDebugValue) to control this.
func (*TestingLogger) AssertionsPassed ¶
func (tw *TestingLogger) AssertionsPassed() bool
func (TestingLogger) Warn ¶ added in v1.0.0
func (l TestingLogger) Warn(msg string, keyVals ...interface{})
func (*TestingLogger) WithTimestamp ¶ added in v1.0.0
func (tw *TestingLogger) WithTimestamp() *TestingLogger
WithTimestamp returns a new TestingLogger with timestamp enabled.