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.

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