From 25a8b5708b5592123e906ff6272f0325fc237d63 Mon Sep 17 00:00:00 2001 From: aeneasr <3372410+aeneasr@users.noreply.github.com> Date: Tue, 4 Aug 2020 13:37:40 +0200 Subject: [PATCH] fix(logrusx): prettify on json_pretty only --- logrusx/logrus.go | 6 +++--- logrusx/logrus_test.go | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/logrusx/logrus.go b/logrusx/logrus.go index 6e36bab7..c50427c3 100644 --- a/logrusx/logrus.go +++ b/logrusx/logrus.go @@ -35,9 +35,9 @@ func newLogger(o *options) *logrus.Logger { } else { switch stringsx.Coalesce(o.format, viper.GetString("log.format"), viper.GetString("LOG_FORMAT")) { case "json": - l.Formatter = &logrus.JSONFormatter{ - PrettyPrint: l.IsLevelEnabled(logrus.DebugLevel), - } + l.Formatter = &logrus.JSONFormatter{PrettyPrint: false} + case "json_pretty": + l.Formatter = &logrus.JSONFormatter{PrettyPrint: true} default: l.Formatter = &logrus.TextFormatter{ DisableQuote: true, diff --git a/logrusx/logrus_test.go b/logrusx/logrus_test.go index b76704f2..a5080c76 100644 --- a/logrusx/logrus_test.go +++ b/logrusx/logrus_test.go @@ -42,7 +42,7 @@ func TestOptions(t *testing.T) { func TestJSONFormatter(t *testing.T) { t.Run("pretty=true", func(t *testing.T) { - l := New("logrusx-audit", "v0.0.0", ForceFormat("json"), ForceLevel(logrus.DebugLevel)) + l := New("logrusx-audit", "v0.0.0", ForceFormat("json_pretty"), ForceLevel(logrus.DebugLevel)) var b bytes.Buffer l.Logrus().Out = &b @@ -52,7 +52,7 @@ func TestJSONFormatter(t *testing.T) { }) t.Run("pretty=false", func(t *testing.T) { - l := New("logrusx-audit", "v0.0.0", ForceFormat("json"), ForceLevel(logrus.InfoLevel)) + l := New("logrusx-audit", "v0.0.0", ForceFormat("json"), ForceLevel(logrus.DebugLevel)) var b bytes.Buffer l.Logrus().Out = &b