Documentation ¶
Overview ¶
package logger exports multiple type loggers:
- the *Logger type is a wrapper over uber/zap#SugaredLogger with added conditional utilities.
- the Default instance is exported and used in all top-level functions (similar to godoc.org/log). You can use this dirrectly but the recommended way is to create a new *Logger for your module using Named(), eg: logger.Default.Named("<my-package-name>")
- ProductionLogger() builds a *Logger which stores logs on disk.
- CreateTestLogger() prints log lines formatted for test runners. Use this in your tests!
- CreateMemoryTestLogger() records logs in memory. It's useful for making assertions on the produced logs.
Package logger is used to store details of events in the node. Events can be categorized by Trace, Debug, Info, Error, Fatal, and Panic.
Index ¶
- func Debug(args ...interface{})
- func Debugf(format string, values ...interface{})
- func Debugw(msg string, keysAndValues ...interface{})
- func Error(args ...interface{})
- func ErrorIf(err error, optionalMsg ...string)
- func ErrorIfCalling(f func() error, optionalMsg ...string)
- func Errorf(format string, values ...interface{})
- func Errorw(msg string, keysAndValues ...interface{})
- func Fatal(args ...interface{})
- func Fatalf(format string, values ...interface{})
- func Info(args ...interface{})
- func Infof(format string, values ...interface{})
- func Infow(msg string, keysAndValues ...interface{})
- func Panic(args ...interface{})
- func PanicIf(err error)
- func Panicf(format string, values ...interface{})
- func SetLogger(newLogger *Logger)
- func Sync() error
- func Trace(args ...interface{})
- func Tracef(format string, values ...interface{})
- func Tracew(msg string, keysAndValues ...interface{})
- func Warn(args ...interface{})
- func WarnIf(err error)
- func Warnf(format string, values ...interface{})
- func Warnw(msg string, keysAndValues ...interface{})
- type Logger
- type MemorySink
- type PrettyConsole
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Debugf ¶
func Debugf(format string, values ...interface{})
Debugf formats and then logs the message.
func Debugw ¶
func Debugw(msg string, keysAndValues ...interface{})
Debugw logs a debug message and any additional given information.
func ErrorIfCalling ¶
func Errorf ¶
func Errorf(format string, values ...interface{})
Errorf logs a message at the error level using Sprintf.
func Errorw ¶
func Errorw(msg string, keysAndValues ...interface{})
Errorw logs an error message, any additional given information, and includes stack trace.
func Fatalf ¶
func Fatalf(format string, values ...interface{})
Fatalf logs a message at the fatal level using Sprintf.
func Infof ¶
func Infof(format string, values ...interface{})
Infof formats and then logs the message.
func Infow ¶
func Infow(msg string, keysAndValues ...interface{})
Infow logs an info message and any additional given information.
func Panicf ¶
func Panicf(format string, values ...interface{})
Panicf formats and then logs the message before panicking.
func SetLogger ¶
func SetLogger(newLogger *Logger)
SetLogger sets the internal logger to the given input.
DEPRECATED this method is deprecated because it leads to race conditions. Instead, you should fork the logger.Default instance to create a new logger for your module. Eg: logger.Default.Named("<my-package-name>")
func Trace ¶
func Trace(args ...interface{})
Trace is a shim stand-in for when we have real trace-level logging support
func Tracef ¶
func Tracef(format string, values ...interface{})
Tracef is a shim stand-in for when we have real trace-level logging support
func Tracew ¶
func Tracew(msg string, keysAndValues ...interface{})
Tracew is a shim stand-in for when we have real trace-level logging support
Types ¶
type Logger ¶
type Logger struct {
*zap.SugaredLogger
}
Logger is the main interface of this package. It implements uber/zap's SugaredLogger interface and adds conditional logging helpers.
var ( // Default logger for use throughout the project. // All the package-level functions are calling Default. Default *Logger )
func CreateMemoryTestLogger ¶
CreateMemoryTestLogger creates a logger that only directs output to the buffer testMemoryLog.
func CreateProductionLogger ¶
CreateProductionLogger returns a log config for the passed directory with the given LogLevel and customizes stdout for pretty printing.
func CreateTestLogger ¶
CreateTestLogger creates a logger that directs output to PrettyConsole configured for test output, and to the buffer testMemoryLog.
func (*Logger) ErrorIfCalling ¶
ErrorIfCalling calls the given function and logs the error of it if there is.
type MemorySink ¶
type MemorySink struct {
// contains filtered or unexported fields
}
MemorySink implements zap.Sink by writing all messages to a buffer.
func MemoryLogTestingOnly ¶
func MemoryLogTestingOnly() *MemorySink
func (*MemorySink) Close ¶
func (s *MemorySink) Close() error
Close is a dummy method to satisfy the zap.Sink interface
func (*MemorySink) String ¶
func (s *MemorySink) String() string
String returns the full log contents, as a string
func (*MemorySink) Sync ¶
func (s *MemorySink) Sync() error
Sync is a dummy method to satisfy the zap.Sink interface
type PrettyConsole ¶
PrettyConsole wraps a Sink (Writer, Syncer, Closer), usually stdout, and formats the incoming json bytes with colors and white space for readability before passing on to the underlying Writer in Sink.