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 directly 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.
- TestLogger() prints log lines formatted for test runners. Use this in your tests!
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 ¶
- Constants
- func Debug(args ...interface{})
- func Debugf(format string, values ...interface{})
- func Debugw(msg string, keysAndValues ...interface{})
- func Error(args ...interface{})
- func ErrorIfCalling(f func() error)
- func Errorf(format string, values ...interface{})
- func Errorw(msg string, keysAndValues ...interface{})
- func Fatal(args ...interface{})
- func Fatalf(format string, values ...interface{})
- func Fatalw(msg string, keysAndValues ...interface{})
- func GetLogServices() []string
- func Infof(format string, values ...interface{})
- func Infow(msg string, keysAndValues ...interface{})
- func InitColor(c bool)
- func InitLogger(newLogger Logger)
- func NewOCRWrapper(l Logger, trace bool, saveError func(string)) ocrtypes.Logger
- func NewORM(db *gorm.DB) *orm
- func Panicf(format string, values ...interface{})
- func Sync() error
- func Warn(args ...interface{})
- func Warnf(format string, values ...interface{})
- func Warnw(msg string, keysAndValues ...interface{})
- type Config
- type GormWrapper
- func (o *GormWrapper) Error(ctx context.Context, s string, i ...interface{})
- func (o *GormWrapper) Info(ctx context.Context, s string, i ...interface{})
- func (o *GormWrapper) LogAllQueries(b bool)
- func (o *GormWrapper) LogMode(level gormlogger.LogLevel) gormlogger.Interface
- func (o *GormWrapper) Trace(ctx context.Context, begin time.Time, fc func() (string, int64), err error)
- func (o *GormWrapper) Warn(ctx context.Context, s string, i ...interface{})
- type LogConfig
- type Logger
- type MemorySink
- type ORM
- type PrettyConsole
- type T
Constants ¶
const ( HeadTracker = "head_tracker" FluxMonitor = "fluxmonitor" Keeper = "keeper" )
Constants for service names for package specific logging configuration
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 ¶ added in v1.10.16
func ErrorIfCalling(f func() error)
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 Fatalw ¶ added in v1.10.16
func Fatalw(msg string, keysAndValues ...interface{})
Fatalw logs a message and exits the application
func GetLogServices ¶ added in v1.10.16
func GetLogServices() []string
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 InitColor ¶ added in v1.10.17
func InitColor(c bool)
InitColor explicitly sets the global color.NoColor option. Not safe for concurrent use. Only to be called from init().
func InitLogger ¶ added in v1.10.17
func InitLogger(newLogger Logger)
InitLogger sets the Default logger to newLogger. Not safe for concurrent use, so must be called from init() or the main goroutine during initialization.
You probably don't want to use this. Instead, you should fork the logger.Default instance to create a new logger: Eg: logger.Default.Named("<my-service-name>")
func NewOCRWrapper ¶ added in v1.10.17
func Panicf ¶
func Panicf(format string, values ...interface{})
Panicf formats and then logs the message before panicking.
Types ¶
type GormWrapper ¶ added in v1.10.17
type GormWrapper struct { Logger // contains filtered or unexported fields }
func NewGormWrapper ¶ added in v1.10.17
func NewGormWrapper(logger Logger, logAllQueries bool, slowThreshold time.Duration) *GormWrapper
func (*GormWrapper) Error ¶ added in v1.10.17
func (o *GormWrapper) Error(ctx context.Context, s string, i ...interface{})
func (*GormWrapper) Info ¶ added in v1.10.17
func (o *GormWrapper) Info(ctx context.Context, s string, i ...interface{})
func (*GormWrapper) LogAllQueries ¶ added in v1.10.17
func (o *GormWrapper) LogAllQueries(b bool)
func (*GormWrapper) LogMode ¶ added in v1.10.17
func (o *GormWrapper) LogMode(level gormlogger.LogLevel) gormlogger.Interface
Noop
func (*GormWrapper) Trace ¶ added in v1.10.17
func (o *GormWrapper) Trace(ctx context.Context, begin time.Time, fc func() (string, int64), err error)
This is called at the end of every gorm v2 query. We always log the sql queries for errors and slow queries (warns). Need to set LOG_SQL=true to enable all queries.
type LogConfig ¶ added in v1.10.16
type LogConfig struct { ID int64 `gorm:"primary_key"` ServiceName string `gorm:"not null"` LogLevel string `gorm:"not null"` CreatedAt time.Time UpdatedAt time.Time }
LogConfig stores key value pairs for configuring package specific logging
type Logger ¶
type Logger interface { // With creates a new Logger with the given arguments With(args ...interface{}) Logger // Named creates a new Logger sub-scoped with name. // Names are inherited and dot-separated. // a := l.Named("a") // logger=a // b := a.Named("b") // logger=a.b Named(name string) Logger // NewRootLogger creates a new root Logger with an independent log level // unaffected by upstream calls to SetLogLevel. NewRootLogger(lvl zapcore.Level) (Logger, error) // SetLogLevel changes the log level for this and all connected Loggers. SetLogLevel(zapcore.Level) Debug(args ...interface{}) Info(args ...interface{}) Warn(args ...interface{}) Error(args ...interface{}) Fatal(args ...interface{}) Panic(args ...interface{}) Debugf(format string, values ...interface{}) Infof(format string, values ...interface{}) Warnf(format string, values ...interface{}) Errorf(format string, values ...interface{}) Fatalf(format string, values ...interface{}) Debugw(msg string, keysAndValues ...interface{}) Infow(msg string, keysAndValues ...interface{}) Warnw(msg string, keysAndValues ...interface{}) Errorw(msg string, keysAndValues ...interface{}) Fatalw(msg string, keysAndValues ...interface{}) Panicw(msg string, keysAndValues ...interface{}) // WarnIf logs the error if present. WarnIf(err error, msg string) // ErrorIf logs the error if present. ErrorIf(err error, msg string) PanicIf(err error, msg string) // ErrorIfCalling calls fn and logs any returned error along with func name. ErrorIfCalling(fn func() error) // Sync flushes any buffered log entries. // Some insignificant errors are suppressed. Sync() error // contains filtered or unexported methods }
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 )
var NullLogger Logger
func NewNullLogger ¶ added in v1.10.17
func NewNullLogger() Logger
func ProductionLogger ¶ added in v1.10.17
ProductionLogger returns a custom logger for the config's root directory and LogLevel, with pretty printing for stdout. If LOG_TO_DISK is false, the logger will only log to stdout.
func TestLogger ¶ added in v1.10.17
TestLogger creates a logger that directs output to PrettyConsole configured for test output, and to the buffer testMemoryLog. t is optional. Log level is derived from the LOG_LEVEL env var.
type MemorySink ¶ added in v1.10.16
type MemorySink struct {
// contains filtered or unexported fields
}
MemorySink implements zap.Sink by writing all messages to a buffer.
func MemoryLogTestingOnly ¶ added in v1.10.16
func MemoryLogTestingOnly() *MemorySink
func (*MemorySink) Close ¶ added in v1.10.16
func (s *MemorySink) Close() error
Close is a dummy method to satisfy the zap.Sink interface
func (*MemorySink) Reset ¶ added in v1.10.17
func (s *MemorySink) Reset()
func (*MemorySink) String ¶ added in v1.10.16
func (s *MemorySink) String() string
String returns the full log contents, as a string
func (*MemorySink) Sync ¶ added in v1.10.16
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.