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.

55 lines
1.2 KiB

10 years ago
  1. package logger
  2. import (
  3. "os"
  4. "github.com/tendermint/tendermint/Godeps/_workspace/src/github.com/tendermint/log15"
  5. . "github.com/tendermint/tendermint/common"
  6. )
  7. var rootHandler log15.Handler
  8. func init() {
  9. Reset()
  10. }
  11. // You might want to call this after resetting tendermint/config.
  12. func Reset() {
  13. var logLevel string = "debug"
  14. if config != nil {
  15. logLevel = config.GetString("log_level")
  16. }
  17. // stdout handler
  18. //handlers := []log15.Handler{}
  19. stdoutHandler := log15.LvlFilterHandler(
  20. getLevel(logLevel),
  21. log15.StreamHandler(os.Stdout, log15.TerminalFormat()),
  22. )
  23. //handlers = append(handlers, stdoutHandler)
  24. // Set rootHandler.
  25. //rootHandler = log15.MultiHandler(handlers...)
  26. rootHandler = stdoutHandler
  27. // By setting handlers on the root, we handle events from all loggers.
  28. log15.Root().SetHandler(rootHandler)
  29. }
  30. // See binary/log for an example of usage.
  31. func RootHandler() log15.Handler {
  32. return rootHandler
  33. }
  34. func New(ctx ...interface{}) log15.Logger {
  35. return log15.Root().New(ctx...)
  36. }
  37. func getLevel(lvlString string) log15.Lvl {
  38. lvl, err := log15.LvlFromString(lvlString)
  39. if err != nil {
  40. Exit(Fmt("Invalid log level %v: %v", lvlString, err))
  41. }
  42. return lvl
  43. }