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