Skip to content

Commit

Permalink
fix(logrusx): prettify on json_pretty only (#182)
Browse files Browse the repository at this point in the history
  • Loading branch information
aeneasr authored Aug 4, 2020
1 parent 72978df commit 59ba571
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions logrusx/logrus.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions logrusx/logrus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand Down

0 comments on commit 59ba571

Please sign in to comment.