diff options
author | Péter Szilágyi <peterke@gmail.com> | 2017-02-28 00:05:50 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-02-28 00:05:50 +0800 |
commit | 48bc07ae976a7940f75adaa68a4ea3887f5fad6c (patch) | |
tree | cf19edb8ed153797edc8da7772f6d7f0671c410b /internal | |
parent | e8b3e226124d2b0234c36ef2ca9221dc95c56a1a (diff) | |
parent | d0eba23af373bb54b00b242ccee4239fc9afd873 (diff) | |
download | go-tangerine-48bc07ae976a7940f75adaa68a4ea3887f5fad6c.tar.gz go-tangerine-48bc07ae976a7940f75adaa68a4ea3887f5fad6c.tar.zst go-tangerine-48bc07ae976a7940f75adaa68a4ea3887f5fad6c.zip |
Merge pull request #3708 from fjl/log-letter
log: fix annoyances
Diffstat (limited to 'internal')
-rw-r--r-- | internal/debug/flags.go | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/internal/debug/flags.go b/internal/debug/flags.go index 29d1f3388..f95251939 100644 --- a/internal/debug/flags.go +++ b/internal/debug/flags.go @@ -18,12 +18,15 @@ package debug import ( "fmt" + "io" "net/http" _ "net/http/pprof" "os" "runtime" "github.com/ethereum/go-ethereum/log" + "github.com/ethereum/go-ethereum/log/term" + colorable "github.com/mattn/go-colorable" "gopkg.in/urfave/cli.v1" ) @@ -87,16 +90,22 @@ var Flags = []cli.Flag{ memprofilerateFlag, blockprofilerateFlag, cpuprofileFlag, traceFlag, } -// glogger is the glog handler used by Geth, allowing the debug APIs to modify -// verbosity levels, vmodules and backtrace locations. -var glogger = log.NewGlogHandler(log.StreamHandler(os.Stderr, log.TerminalFormat())) +var glogger *log.GlogHandler + +func init() { + usecolor := term.IsTty(os.Stderr.Fd()) && os.Getenv("TERM") != "dumb" + output := io.Writer(os.Stderr) + if usecolor { + output = colorable.NewColorableStderr() + } + glogger = log.NewGlogHandler(log.StreamHandler(output, log.TerminalFormat(usecolor))) +} // Setup initializes profiling and logging based on the CLI flags. // It should be called as early as possible in the program. func Setup(ctx *cli.Context) error { // logging log.PrintOrigins(ctx.GlobalBool(debugFlag.Name)) - glogger.Verbosity(log.Lvl(ctx.GlobalInt(verbosityFlag.Name))) glogger.Vmodule(ctx.GlobalString(vmoduleFlag.Name)) glogger.BacktraceAt(ctx.GlobalString(backtraceAtFlag.Name)) |