Browse Source

Add BypassHandler and NewBypass to bypass main filter

pull/1842/head
Jae Kwon 9 years ago
parent
commit
acdbd88e88
1 changed files with 28 additions and 9 deletions
  1. +28
    -9
      log.go

+ 28
- 9
log.go View File

@ -7,7 +7,9 @@ import (
"github.com/tendermint/log15"
)
var rootHandler log15.Handler
//var rootHandler log15.Handler
var mainHandler log15.Handler
var bypassHandler log15.Handler
func init() {
Reset()
@ -21,31 +23,48 @@ func Reset() {
logLevel = config.GetString("log_level")
}
// stdout handler
// main handler
//handlers := []log15.Handler{}
stdoutHandler := log15.LvlFilterHandler(
mainHandler = log15.LvlFilterHandler(
getLevel(logLevel),
log15.StreamHandler(os.Stdout, log15.TerminalFormat()),
)
//handlers = append(handlers, stdoutHandler)
//handlers = append(handlers, mainHandler)
// bypass handler for not filtering on global logLevel.
bypassHandler = log15.StreamHandler(os.Stdout, log15.TerminalFormat())
//handlers = append(handlers, bypassHandler)
// Set rootHandler.
//rootHandler = log15.MultiHandler(handlers...)
rootHandler = stdoutHandler
// By setting handlers on the root, we handle events from all loggers.
log15.Root().SetHandler(rootHandler)
log15.Root().SetHandler(mainHandler)
}
// See go-wire/log for an example of usage.
func MainHandler() log15.Handler {
return mainHandler
}
// See binary/log for an example of usage.
func RootHandler() log15.Handler {
return rootHandler
func BypassHandler() log15.Handler {
return bypassHandler
}
func New(ctx ...interface{}) log15.Logger {
return NewMain(ctx...)
}
func NewMain(ctx ...interface{}) log15.Logger {
return log15.Root().New(ctx...)
}
func NewBypass(ctx ...interface{}) log15.Logger {
bypass := log15.New(ctx...)
bypass.SetHandler(bypassHandler)
return bypass
}
func getLevel(lvlString string) log15.Lvl {
lvl, err := log15.LvlFromString(lvlString)
if err != nil {


Loading…
Cancel
Save