You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

77 lines
1.7 KiB

9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
  1. package logger
  2. import (
  3. "os"
  4. . "github.com/tendermint/tmlibs/common"
  5. "github.com/tendermint/log15"
  6. )
  7. var mainHandler log15.Handler
  8. var bypassHandler log15.Handler
  9. func init() {
  10. resetWithLogLevel("debug")
  11. }
  12. func SetLogLevel(logLevel string) {
  13. resetWithLogLevel(logLevel)
  14. }
  15. func resetWithLogLevel(logLevel string) {
  16. // main handler
  17. //handlers := []log15.Handler{}
  18. mainHandler = log15.LvlFilterHandler(
  19. getLevel(logLevel),
  20. log15.StreamHandler(os.Stdout, log15.TerminalFormat()),
  21. )
  22. //handlers = append(handlers, mainHandler)
  23. // bypass handler for not filtering on global logLevel.
  24. bypassHandler = log15.StreamHandler(os.Stdout, log15.TerminalFormat())
  25. //handlers = append(handlers, bypassHandler)
  26. // By setting handlers on the root, we handle events from all loggers.
  27. log15.Root().SetHandler(mainHandler)
  28. }
  29. // See go-wire/log for an example of usage.
  30. func MainHandler() log15.Handler {
  31. return mainHandler
  32. }
  33. func BypassHandler() log15.Handler {
  34. return bypassHandler
  35. }
  36. func New(ctx ...interface{}) log15.Logger {
  37. return NewMain(ctx...)
  38. }
  39. func NewMain(ctx ...interface{}) log15.Logger {
  40. return log15.Root().New(ctx...)
  41. }
  42. func NewBypass(ctx ...interface{}) log15.Logger {
  43. bypass := log15.New(ctx...)
  44. bypass.SetHandler(bypassHandler)
  45. return bypass
  46. }
  47. func getLevel(lvlString string) log15.Lvl {
  48. lvl, err := log15.LvlFromString(lvlString)
  49. if err != nil {
  50. Exit(Fmt("Invalid log level %v: %v", lvlString, err))
  51. }
  52. return lvl
  53. }
  54. //----------------------------------------
  55. // Exported from log15
  56. var LvlFilterHandler = log15.LvlFilterHandler
  57. var LvlDebug = log15.LvlDebug
  58. var LvlInfo = log15.LvlInfo
  59. var LvlNotice = log15.LvlNotice
  60. var LvlWarn = log15.LvlWarn
  61. var LvlError = log15.LvlError