10 log "github.com/sirupsen/logrus"
11 "github.com/tendermint/tmlibs/cli"
13 "github.com/vapor/cmd/bytomd/commands"
14 "github.com/vapor/config"
17 // ContextHook is a hook for logrus.
18 type ContextHook struct{}
20 // Levels returns the whole levels.
21 func (hook ContextHook) Levels() []log.Level {
25 // Fire helps logrus record the related file, function and line.
26 func (hook ContextHook) Fire(entry *log.Entry) error {
27 pc := make([]uintptr, 3, 3)
28 cnt := runtime.Callers(6, pc)
30 for i := 0; i < cnt; i++ {
31 fu := runtime.FuncForPC(pc[i] - 1)
33 if !strings.Contains(name, "github.com/Sirupsen/log") {
34 file, line := fu.FileLine(pc[i] - 1)
35 entry.Data["file"] = path.Base(file)
36 entry.Data["func"] = path.Base(name)
37 entry.Data["line"] = line
45 log.SetFormatter(&log.TextFormatter{TimestampFormat: time.StampMilli, DisableColors: true})
47 // If environment variable BYTOM_DEBUG is not empty,
48 // then add the hook to logrus and set the log level to DEBUG
49 if os.Getenv("BYTOM_DEBUG") != "" {
50 log.AddHook(ContextHook{})
55 cmd := cli.PrepareBaseCmd(commands.RootCmd, "TM", os.ExpandEnv(config.DefaultDataDir()))