2023-06-23 12:42:55 +00:00
|
|
|
package log
|
|
|
|
|
|
|
|
import (
|
2023-06-16 09:53:15 +00:00
|
|
|
// geth_log "github.com/ethereum/go-ethereum/log"
|
2023-06-23 12:42:55 +00:00
|
|
|
"github.com/inconshreveable/log15"
|
|
|
|
"github.com/openrelayxyz/plugeth-utils/core"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Logger = core.Logger
|
|
|
|
|
|
|
|
var (
|
|
|
|
DefaultLogger core.Logger
|
2023-06-16 09:53:15 +00:00
|
|
|
|
|
|
|
TestLogger = Log15Logger()
|
2023-06-23 12:42:55 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
// The plugeth logger is only initialized with the geth runtime,
|
|
|
|
// but tests expect to have a logger available, so default to this.
|
2023-06-16 09:53:15 +00:00
|
|
|
DefaultLogger = TestLogger
|
2023-06-23 12:42:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func Trace(m string, a ...interface{}) { DefaultLogger.Trace(m, a...) }
|
|
|
|
func Debug(m string, a ...interface{}) { DefaultLogger.Debug(m, a...) }
|
|
|
|
func Info(m string, a ...interface{}) { DefaultLogger.Info(m, a...) }
|
|
|
|
func Warn(m string, a ...interface{}) { DefaultLogger.Warn(m, a...) }
|
|
|
|
func Crit(m string, a ...interface{}) { DefaultLogger.Crit(m, a...) }
|
|
|
|
func Error(m string, a ...interface{}) { DefaultLogger.Error(m, a...) }
|
|
|
|
|
2023-06-16 09:53:15 +00:00
|
|
|
func SetDefaultLogger(l core.Logger) {
|
|
|
|
// gethlogger, ok := l.(geth_log.Logger)
|
|
|
|
// if !ok {
|
|
|
|
// panic("not a geth Logger")
|
|
|
|
// }
|
|
|
|
DefaultLogger = l
|
|
|
|
}
|
|
|
|
|
|
|
|
// Log15Logger returns a logger satisfying the same interface as geth's
|
|
|
|
func Log15Logger(ctx ...interface{}) wrapLog15 {
|
|
|
|
return wrapLog15{log15.New(ctx...)}
|
|
|
|
}
|
|
|
|
|
2023-06-23 12:42:55 +00:00
|
|
|
type wrapLog15 struct{ log15.Logger }
|
|
|
|
|
|
|
|
func (l wrapLog15) New(ctx ...interface{}) Logger {
|
|
|
|
return wrapLog15{l.Logger.New(ctx...)}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (l wrapLog15) Trace(m string, a ...interface{}) {
|
|
|
|
l.Logger.Debug(m, a...)
|
|
|
|
}
|
|
|
|
|
2023-06-16 09:53:15 +00:00
|
|
|
func (l wrapLog15) SetLevel(lvl int) {
|
|
|
|
l.SetHandler(log15.LvlFilterHandler(log15.Lvl(lvl), l.GetHandler()))
|
2023-06-23 12:42:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// New returns a Logger that includes the contextual args in all output
|
|
|
|
// (workaround for missing method in plugeth)
|
|
|
|
func New(ctx ...interface{}) Logger {
|
|
|
|
return ctxLogger{DefaultLogger, ctx}
|
|
|
|
}
|
|
|
|
|
|
|
|
type ctxLogger struct {
|
|
|
|
base Logger
|
|
|
|
ctx []interface{}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (l ctxLogger) Trace(m string, a ...interface{}) { l.base.Trace(m, append(l.ctx, a...)...) }
|
|
|
|
func (l ctxLogger) Debug(m string, a ...interface{}) { l.base.Debug(m, append(l.ctx, a...)...) }
|
|
|
|
func (l ctxLogger) Info(m string, a ...interface{}) { l.base.Info(m, append(l.ctx, a...)...) }
|
|
|
|
func (l ctxLogger) Warn(m string, a ...interface{}) { l.base.Warn(m, append(l.ctx, a...)...) }
|
|
|
|
func (l ctxLogger) Crit(m string, a ...interface{}) { l.base.Crit(m, append(l.ctx, a...)...) }
|
|
|
|
func (l ctxLogger) Error(m string, a ...interface{}) { l.base.Error(m, append(l.ctx, a...)...) }
|