aboutsummaryrefslogtreecommitdiffstats
path: root/log/format.go
diff options
context:
space:
mode:
authorFelix Lange <fjl@twurst.com>2017-02-24 02:31:13 +0800
committerFelix Lange <fjl@twurst.com>2017-02-27 22:33:12 +0800
commitd0eba23af373bb54b00b242ccee4239fc9afd873 (patch)
treecf19edb8ed153797edc8da7772f6d7f0671c410b /log/format.go
parent43362ab4fb561323e1a766405eaa8f82dec4a280 (diff)
downloaddexon-d0eba23af373bb54b00b242ccee4239fc9afd873.tar
dexon-d0eba23af373bb54b00b242ccee4239fc9afd873.tar.gz
dexon-d0eba23af373bb54b00b242ccee4239fc9afd873.tar.bz2
dexon-d0eba23af373bb54b00b242ccee4239fc9afd873.tar.lz
dexon-d0eba23af373bb54b00b242ccee4239fc9afd873.tar.xz
dexon-d0eba23af373bb54b00b242ccee4239fc9afd873.tar.zst
dexon-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 'log/format.go')
-rw-r--r--log/format.go30
1 files changed, 16 insertions, 14 deletions
diff --git a/log/format.go b/log/format.go
index c61a4d82a..f32fcf744 100644
--- a/log/format.go
+++ b/log/format.go
@@ -69,22 +69,24 @@ func (f formatFunc) Format(r *Record) []byte {
//
// [May 16 20:58:45] [DBUG] remove route ns=haproxy addr=127.0.0.1:50002
//
-func TerminalFormat() Format {
+func TerminalFormat(usecolor bool) Format {
return FormatFunc(func(r *Record) []byte {
var color = 0
- switch r.Lvl {
- case LvlCrit:
- color = 35
- case LvlError:
- color = 31
- case LvlWarn:
- color = 33
- case LvlInfo:
- color = 32
- case LvlDebug:
- color = 36
- case LvlTrace:
- color = 34
+ if usecolor {
+ switch r.Lvl {
+ case LvlCrit:
+ color = 35
+ case LvlError:
+ color = 31
+ case LvlWarn:
+ color = 33
+ case LvlInfo:
+ color = 32
+ case LvlDebug:
+ color = 36
+ case LvlTrace:
+ color = 34
+ }
}
b := &bytes.Buffer{}