aboutsummaryrefslogtreecommitdiffstats
path: root/log
diff options
context:
space:
mode:
authorPéter Szilágyi <peterke@gmail.com>2017-02-28 00:05:50 +0800
committerGitHub <noreply@github.com>2017-02-28 00:05:50 +0800
commit48bc07ae976a7940f75adaa68a4ea3887f5fad6c (patch)
treecf19edb8ed153797edc8da7772f6d7f0671c410b /log
parente8b3e226124d2b0234c36ef2ca9221dc95c56a1a (diff)
parentd0eba23af373bb54b00b242ccee4239fc9afd873 (diff)
downloaddexon-48bc07ae976a7940f75adaa68a4ea3887f5fad6c.tar
dexon-48bc07ae976a7940f75adaa68a4ea3887f5fad6c.tar.gz
dexon-48bc07ae976a7940f75adaa68a4ea3887f5fad6c.tar.bz2
dexon-48bc07ae976a7940f75adaa68a4ea3887f5fad6c.tar.lz
dexon-48bc07ae976a7940f75adaa68a4ea3887f5fad6c.tar.xz
dexon-48bc07ae976a7940f75adaa68a4ea3887f5fad6c.tar.zst
dexon-48bc07ae976a7940f75adaa68a4ea3887f5fad6c.zip
Merge pull request #3708 from fjl/log-letter
log: fix annoyances
Diffstat (limited to 'log')
-rw-r--r--log/format.go36
-rw-r--r--log/logger.go22
-rw-r--r--log/root.go16
3 files changed, 42 insertions, 32 deletions
diff --git a/log/format.go b/log/format.go
index 2a3790501..f32fcf744 100644
--- a/log/format.go
+++ b/log/format.go
@@ -69,26 +69,28 @@ 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{}
- lvl := strings.ToUpper(r.Lvl.String())
+ lvl := r.Lvl.AlignedString()
if atomic.LoadUint32(&locationEnabled) != 0 {
// Log origin printing was requested, format the location path and line number
location := fmt.Sprintf("%+v", r.Call)
@@ -107,13 +109,13 @@ func TerminalFormat() Format {
if color > 0 {
fmt.Fprintf(b, "\x1b[%dm%s\x1b[0m[%s|%s]%s %s ", color, lvl, r.Time.Format(termTimeFormat), location, padding, r.Msg)
} else {
- fmt.Fprintf(b, "[%s] [%s|%s]%s %s ", lvl, r.Time.Format(termTimeFormat), location, padding, r.Msg)
+ fmt.Fprintf(b, "%s[%s|%s]%s %s ", lvl, r.Time.Format(termTimeFormat), location, padding, r.Msg)
}
} else {
if color > 0 {
fmt.Fprintf(b, "\x1b[%dm%s\x1b[0m[%s] %s ", color, lvl, r.Time.Format(termTimeFormat), r.Msg)
} else {
- fmt.Fprintf(b, "[%s] [%s] %s ", lvl, r.Time.Format(termTimeFormat), r.Msg)
+ fmt.Fprintf(b, "%s[%s] %s ", lvl, r.Time.Format(termTimeFormat), r.Msg)
}
}
// try to justify the log output for short messages
diff --git a/log/logger.go b/log/logger.go
index a7f7d9df7..15c83a9b2 100644
--- a/log/logger.go
+++ b/log/logger.go
@@ -24,7 +24,27 @@ const (
LvlTrace
)
-// Returns the name of a Lvl
+// Aligned returns a 5-character string containing the name of a Lvl.
+func (l Lvl) AlignedString() string {
+ switch l {
+ case LvlTrace:
+ return "TRACE"
+ case LvlDebug:
+ return "DEBUG"
+ case LvlInfo:
+ return "INFO "
+ case LvlWarn:
+ return "WARN "
+ case LvlError:
+ return "ERROR"
+ case LvlCrit:
+ return "CRIT "
+ default:
+ panic("bad level")
+ }
+}
+
+// Strings returns the name of a Lvl.
func (l Lvl) String() string {
switch l {
case LvlTrace:
diff --git a/log/root.go b/log/root.go
index 12afbf8b7..71b8cef6d 100644
--- a/log/root.go
+++ b/log/root.go
@@ -2,28 +2,16 @@ package log
import (
"os"
-
- "github.com/ethereum/go-ethereum/log/term"
- "github.com/mattn/go-colorable"
)
var (
- root *logger
+ root = &logger{[]interface{}{}, new(swapHandler)}
StdoutHandler = StreamHandler(os.Stdout, LogfmtFormat())
StderrHandler = StreamHandler(os.Stderr, LogfmtFormat())
)
func init() {
- if term.IsTty(os.Stdout.Fd()) {
- StdoutHandler = StreamHandler(colorable.NewColorableStdout(), TerminalFormat())
- }
-
- if term.IsTty(os.Stderr.Fd()) {
- StderrHandler = StreamHandler(colorable.NewColorableStderr(), TerminalFormat())
- }
-
- root = &logger{[]interface{}{}, new(swapHandler)}
- root.SetHandler(LvlFilterHandler(LvlInfo, StdoutHandler))
+ root.SetHandler(DiscardHandler())
}
// New returns a new logger with the given context.