Roy Crihfield
b8fec4b571
Adds a method to perform full-state snapshots by diffing against an empty state trie. This replicates the functionality of `ipld-eth-state-snapshot`, so that code can use this as a library; see: cerc-io/ipld-eth-state-snapshot#1 Note that due to how incremental diffs are processed (updates are processed after the trie has been traversed) the iterator state doesn't fully capture the progress of the diff, so it's not currently feasible to state diffs this way. Full snapshots don't have to worry about updated accounts, so we can support them. Co-authored-by: Thomas E Lackey <telackey@bozemanpass.com> Reviewed-on: #15
70 lines
2.2 KiB
Go
70 lines
2.2 KiB
Go
package log
|
|
|
|
import (
|
|
"github.com/inconshreveable/log15"
|
|
"github.com/openrelayxyz/plugeth-utils/core"
|
|
)
|
|
|
|
type Logger = core.Logger
|
|
|
|
var (
|
|
DefaultLogger core.Logger
|
|
|
|
TestLogger = Log15Logger()
|
|
)
|
|
|
|
func init() {
|
|
// The plugeth logger is only initialized with the geth runtime,
|
|
// but tests expect to have a logger available, so default to this.
|
|
DefaultLogger = TestLogger
|
|
TestLogger.SetLevel(int(log15.LvlInfo))
|
|
}
|
|
|
|
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...) }
|
|
|
|
func SetDefaultLogger(l core.Logger) {
|
|
DefaultLogger = l
|
|
}
|
|
|
|
// Log15Logger returns a logger satisfying the same interface as geth's
|
|
func Log15Logger(ctx ...interface{}) wrapLog15 {
|
|
return wrapLog15{log15.New(ctx...)}
|
|
}
|
|
|
|
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...)
|
|
}
|
|
|
|
func (l wrapLog15) SetLevel(lvl int) {
|
|
l.SetHandler(log15.LvlFilterHandler(log15.Lvl(lvl), l.GetHandler()))
|
|
}
|
|
|
|
// 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...)...) }
|