2017-08-10 13:35:58 +00:00
|
|
|
package log
|
|
|
|
|
|
|
|
import (
|
2017-08-24 08:50:16 +00:00
|
|
|
"fmt"
|
|
|
|
"strings"
|
|
|
|
|
2017-08-10 13:35:58 +00:00
|
|
|
"github.com/ethereum/go-ethereum/log"
|
|
|
|
)
|
|
|
|
|
2017-08-24 08:50:16 +00:00
|
|
|
// logger is package scope instance of log.Logger
|
|
|
|
var logger = log.New("geth", "StatusIM")
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
SetLevel("INFO")
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetLevel inits status and ethereum-go logging packages,
|
|
|
|
// enabling logging and setting up proper log level.
|
|
|
|
//
|
|
|
|
// Our log levels are in form "DEBUG|ERROR|WARN|etc", while
|
|
|
|
// ethereum-go expects names in lower case: "debug|error|warn|etc".
|
|
|
|
func SetLevel(level string) {
|
|
|
|
lvl, err := log.LvlFromString(strings.ToLower(level))
|
|
|
|
if err != nil {
|
|
|
|
fmt.Printf("Incorrect log level: %s, using defaults\n", level)
|
|
|
|
lvl = log.LvlInfo
|
|
|
|
}
|
|
|
|
|
|
|
|
setHandler(lvl, log.StdoutHandler)
|
2017-08-10 13:35:58 +00:00
|
|
|
}
|
|
|
|
|
2017-08-24 08:50:16 +00:00
|
|
|
// setHandler is a init helper that allows (re)initialization
|
|
|
|
// with different handler. Useful for testing.
|
|
|
|
func setHandler(lvl log.Lvl, handler log.Handler) {
|
|
|
|
h := log.LvlFilterHandler(lvl, handler)
|
|
|
|
logger.SetHandler(h)
|
|
|
|
log.Root().SetHandler(h) // ethereum-go logger
|
|
|
|
}
|
2017-08-10 13:35:58 +00:00
|
|
|
|
2017-08-24 08:50:16 +00:00
|
|
|
// Trace is a package scope alias for logger.Trace
|
2017-08-10 13:35:58 +00:00
|
|
|
func Trace(msg string, ctx ...interface{}) {
|
2017-08-24 08:50:16 +00:00
|
|
|
logger.Trace(msg, ctx...)
|
2017-08-10 13:35:58 +00:00
|
|
|
}
|
|
|
|
|
2017-08-24 08:50:16 +00:00
|
|
|
// Debug is a package scope for logger.Debug
|
2017-08-10 13:35:58 +00:00
|
|
|
func Debug(msg string, ctx ...interface{}) {
|
2017-08-24 08:50:16 +00:00
|
|
|
logger.Debug(msg, ctx...)
|
2017-08-10 13:35:58 +00:00
|
|
|
}
|
|
|
|
|
2017-08-24 08:50:16 +00:00
|
|
|
// Info is a package scope for logger.Info
|
2017-08-10 13:35:58 +00:00
|
|
|
func Info(msg string, ctx ...interface{}) {
|
2017-08-24 08:50:16 +00:00
|
|
|
logger.Info(msg, ctx...)
|
2017-08-10 13:35:58 +00:00
|
|
|
}
|
|
|
|
|
2017-08-24 08:50:16 +00:00
|
|
|
// Warn is a package scope for logger.Warn
|
2017-08-10 13:35:58 +00:00
|
|
|
func Warn(msg string, ctx ...interface{}) {
|
2017-08-24 08:50:16 +00:00
|
|
|
logger.Warn(msg, ctx...)
|
2017-08-10 13:35:58 +00:00
|
|
|
}
|
|
|
|
|
2017-08-24 08:50:16 +00:00
|
|
|
// Error is a package scope for logger.Error
|
2017-08-10 13:35:58 +00:00
|
|
|
func Error(msg string, ctx ...interface{}) {
|
2017-08-24 08:50:16 +00:00
|
|
|
logger.Error(msg, ctx...)
|
2017-08-10 13:35:58 +00:00
|
|
|
}
|
|
|
|
|
2017-08-24 08:50:16 +00:00
|
|
|
// Crit is a package scope for logger.Crit
|
2017-08-10 13:35:58 +00:00
|
|
|
func Crit(msg string, ctx ...interface{}) {
|
2017-08-24 08:50:16 +00:00
|
|
|
logger.Crit(msg, ctx...)
|
2017-08-10 13:35:58 +00:00
|
|
|
}
|