From bba72ee16106fa32b6b58ba7f0bb2197246a710d Mon Sep 17 00:00:00 2001 From: Tobie Morgan Hitchcock Date: Mon, 14 Jan 2019 10:37:15 +0000 Subject: [PATCH] Add TRACE level logging --- cli/setup.go | 1 + log/hook.go | 2 ++ log/log.go | 12 +++++++++++- log/text.go | 6 +++++- 4 files changed, 19 insertions(+), 2 deletions(-) diff --git a/cli/setup.go b/cli/setup.go index 3a6facb3..a9edd051 100644 --- a/cli/setup.go +++ b/cli/setup.go @@ -227,6 +227,7 @@ func setup() { if opts.Logging.Level != "" { chk = map[string]bool{ + "trace": true, "debug": true, "info": true, "warn": true, diff --git a/log/hook.go b/log/hook.go index bcfa3d59..657f2c25 100644 --- a/log/hook.go +++ b/log/hook.go @@ -45,6 +45,8 @@ func (h *DefaultHook) Fire(entry *logrus.Entry) error { // SetLevel sets the logging level of the logger instance. func (h *DefaultHook) SetLevel(v string) { switch v { + case "trace": + h.l = TraceLevels case "debug": h.l = DebugLevels case "info": diff --git a/log/log.go b/log/log.go index b65638f3..4d9b64b2 100644 --- a/log/log.go +++ b/log/log.go @@ -28,6 +28,7 @@ const ( WarnLevel = logrus.WarnLevel InfoLevel = logrus.InfoLevel DebugLevel = logrus.DebugLevel + TraceLevel = logrus.TraceLevel ) var ( @@ -64,6 +65,15 @@ var ( InfoLevel, DebugLevel, } + TraceLevels = []logrus.Level{ + PanicLevel, + FatalLevel, + ErrorLevel, + WarnLevel, + InfoLevel, + DebugLevel, + TraceLevel, + } ) var log *Logger @@ -77,7 +87,7 @@ func init() { log = &Logger{ &logrus.Logger{ Out: ioutil.Discard, - Level: logrus.DebugLevel, + Level: logrus.TraceLevel, Hooks: logrus.LevelHooks{}, Formatter: &logrus.TextFormatter{}, }, diff --git a/log/text.go b/log/text.go index 3da1afff..7822e2a3 100644 --- a/log/text.go +++ b/log/text.go @@ -126,8 +126,12 @@ func (f *TextFormatter) printColored(b *bytes.Buffer, entry *logrus.Entry, keys var prefix string switch entry.Level { + case logrus.TraceLevel: + color = ansi.White + case logrus.DebugLevel: + color = ansi.Magenta case logrus.InfoLevel: - color = ansi.Green + color = ansi.Blue case logrus.WarnLevel: color = ansi.Yellow case logrus.ErrorLevel: