diff options
author | Péter Szilágyi <peterke@gmail.com> | 2017-02-21 00:05:15 +0800 |
---|---|---|
committer | Péter Szilágyi <peterke@gmail.com> | 2017-02-23 18:00:03 +0800 |
commit | b9d48b4a9300b948362787b90cf3fb7ae77636b4 (patch) | |
tree | 9ed9d16374bd6c7f2cadd0a193e16fc5bc5c9ee3 | |
parent | ec7f81f4bc11c6f8203ec1d3055c9a09a244ff43 (diff) | |
download | go-tangerine-b9d48b4a9300b948362787b90cf3fb7ae77636b4.tar.gz go-tangerine-b9d48b4a9300b948362787b90cf3fb7ae77636b4.tar.zst go-tangerine-b9d48b4a9300b948362787b90cf3fb7ae77636b4.zip |
log: add support for trace level, exit on critical
-rw-r--r-- | log/README_ETHEREUM.md | 1 | ||||
-rw-r--r-- | log/format.go | 2 | ||||
-rw-r--r-- | log/logger.go | 12 | ||||
-rw-r--r-- | log/root.go | 6 | ||||
-rw-r--r-- | log/syslog.go | 2 |
5 files changed, 23 insertions, 0 deletions
diff --git a/log/README_ETHEREUM.md b/log/README_ETHEREUM.md index 6a0b0141b..f6c42ccc0 100644 --- a/log/README_ETHEREUM.md +++ b/log/README_ETHEREUM.md @@ -2,3 +2,4 @@ This package is a fork of https://github.com/inconshreveable/log15, with some minor modifications required by the go-ethereum codebase: * Support for log level `trace` + * Modified behavior to exit on `critical` failure diff --git a/log/format.go b/log/format.go index 376376183..9dcfc8d13 100644 --- a/log/format.go +++ b/log/format.go @@ -58,6 +58,8 @@ func TerminalFormat() Format { color = 32 case LvlDebug: color = 36 + case LvlTrace: + color = 34 } b := &bytes.Buffer{} diff --git a/log/logger.go b/log/logger.go index a9d42b8da..a7f7d9df7 100644 --- a/log/logger.go +++ b/log/logger.go @@ -2,6 +2,7 @@ package log import ( "fmt" + "os" "time" "github.com/go-stack/stack" @@ -20,11 +21,14 @@ const ( LvlWarn LvlInfo LvlDebug + LvlTrace ) // Returns the name of a Lvl func (l Lvl) String() string { switch l { + case LvlTrace: + return "trce" case LvlDebug: return "dbug" case LvlInfo: @@ -44,6 +48,8 @@ func (l Lvl) String() string { // Useful for parsing command line args and configuration files. func LvlFromString(lvlString string) (Lvl, error) { switch lvlString { + case "trace", "trce": + return LvlTrace, nil case "debug", "dbug": return LvlDebug, nil case "info": @@ -87,6 +93,7 @@ type Logger interface { SetHandler(h Handler) // Log a message at the given level with context key/value pairs + Trace(msg string, ctx ...interface{}) Debug(msg string, ctx ...interface{}) Info(msg string, ctx ...interface{}) Warn(msg string, ctx ...interface{}) @@ -128,6 +135,10 @@ func newContext(prefix []interface{}, suffix []interface{}) []interface{} { return newCtx } +func (l *logger) Trace(msg string, ctx ...interface{}) { + l.write(msg, LvlTrace, ctx) +} + func (l *logger) Debug(msg string, ctx ...interface{}) { l.write(msg, LvlDebug, ctx) } @@ -146,6 +157,7 @@ func (l *logger) Error(msg string, ctx ...interface{}) { func (l *logger) Crit(msg string, ctx ...interface{}) { l.write(msg, LvlCrit, ctx) + os.Exit(1) } func (l *logger) GetHandler() Handler { diff --git a/log/root.go b/log/root.go index 39b4c9429..6814cc273 100644 --- a/log/root.go +++ b/log/root.go @@ -41,6 +41,11 @@ func Root() Logger { // etc.) to keep the call depth the same for all paths to logger.write so // runtime.Caller(2) always refers to the call site in client code. +// Trace is a convenient alias for Root().Trace +func Trace(msg string, ctx ...interface{}) { + root.write(msg, LvlTrace, ctx) +} + // Debug is a convenient alias for Root().Debug func Debug(msg string, ctx ...interface{}) { root.write(msg, LvlDebug, ctx) @@ -64,4 +69,5 @@ func Error(msg string, ctx ...interface{}) { // Crit is a convenient alias for Root().Crit func Crit(msg string, ctx ...interface{}) { root.write(msg, LvlCrit, ctx) + os.Exit(1) } diff --git a/log/syslog.go b/log/syslog.go index 4f1097ff9..71a17b30b 100644 --- a/log/syslog.go +++ b/log/syslog.go @@ -38,6 +38,8 @@ func sharedSyslog(fmtr Format, sysWr *syslog.Writer, err error) (Handler, error) syslogFn = sysWr.Info case LvlDebug: syslogFn = sysWr.Debug + case LvlTrace: + syslogFn = func(m string) error { return nil } // There's no syslog level for trace } s := strings.TrimSpace(string(fmtr.Format(r))) |