From d0eba23af373bb54b00b242ccee4239fc9afd873 Mon Sep 17 00:00:00 2001 From: Felix Lange Date: Thu, 23 Feb 2017 19:31:13 +0100 Subject: all: disable log message colors outside of geth Also tweak behaviour so colors are only enabled when stderr is a terminal. --- internal/debug/flags.go | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'internal') 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)) -- cgit v1.2.3