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.

78 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
  1. // DEPRECATED! Use newer log package.
  2. package logger
  3. import (
  4. "os"
  5. "github.com/tendermint/log15"
  6. . "github.com/tendermint/tmlibs/common"
  7. )
  8. var mainHandler log15.Handler
  9. var bypassHandler log15.Handler
  10. func init() {
  11. resetWithLogLevel("debug")
  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. // By setting handlers on the root, we handle events from all loggers.
  28. log15.Root().SetHandler(mainHandler)
  29. }
  30. // See go-wire/log for an example of usage.
  31. func MainHandler() log15.Handler {
  32. return mainHandler
  33. }
  34. func New(ctx ...interface{}) log15.Logger {
  35. return NewMain(ctx...)
  36. }
  37. func BypassHandler() log15.Handler {
  38. return bypassHandler
  39. }
  40. func NewMain(ctx ...interface{}) log15.Logger {
  41. return log15.Root().New(ctx...)
  42. }
  43. func NewBypass(ctx ...interface{}) log15.Logger {
  44. bypass := log15.New(ctx...)
  45. bypass.SetHandler(bypassHandler)
  46. return bypass
  47. }
  48. func getLevel(lvlString string) log15.Lvl {
  49. lvl, err := log15.LvlFromString(lvlString)
  50. if err != nil {
  51. Exit(Fmt("Invalid log level %v: %v", lvlString, err))
  52. }
  53. return lvl
  54. }
  55. //----------------------------------------
  56. // Exported from log15
  57. var LvlFilterHandler = log15.LvlFilterHandler
  58. var LvlDebug = log15.LvlDebug
  59. var LvlInfo = log15.LvlInfo
  60. var LvlNotice = log15.LvlNotice
  61. var LvlWarn = log15.LvlWarn
  62. var LvlError = log15.LvlError