diff options
author | Felix Lange <fjl@twurst.com> | 2017-02-24 02:31:13 +0800 |
---|---|---|
committer | Felix Lange <fjl@twurst.com> | 2017-02-27 22:33:12 +0800 |
commit | d0eba23af373bb54b00b242ccee4239fc9afd873 (patch) | |
tree | cf19edb8ed153797edc8da7772f6d7f0671c410b /internal | |
parent | 43362ab4fb561323e1a766405eaa8f82dec4a280 (diff) | |
download | go-tangerine-d0eba23af373bb54b00b242ccee4239fc9afd873.tar go-tangerine-d0eba23af373bb54b00b242ccee4239fc9afd873.tar.gz go-tangerine-d0eba23af373bb54b00b242ccee4239fc9afd873.tar.bz2 go-tangerine-d0eba23af373bb54b00b242ccee4239fc9afd873.tar.lz go-tangerine-d0eba23af373bb54b00b242ccee4239fc9afd873.tar.xz go-tangerine-d0eba23af373bb54b00b242ccee4239fc9afd873.tar.zst go-tangerine-d0eba23af373bb54b00b242ccee4239fc9afd873.zip |
all: disable log message colors outside of geth
Also tweak behaviour so colors are only enabled when stderr is a terminal.
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)) |