diff --git a/config.dev.toml b/config.dev.toml index 187eeb37..16f11779 100755 --- a/config.dev.toml +++ b/config.dev.toml @@ -81,7 +81,7 @@ LogLevel = "debug" # LogFormat determines the format that logs are output in. Defaults to json. # It is only used when CloudRuntime is set to none. Values can be "plain" or "json". # Env override: ATHENS_LOG_FORMAT -LogFormat = "json" +LogFormat = "plain" # CloudRuntime is the Cloud Provider on which the Proxy/Registry is running. # Currently available options are "GCP", or "none". Defaults to "none" diff --git a/pkg/config/config.go b/pkg/config/config.go index 177a0b52..35aaccc1 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -151,7 +151,7 @@ func defaultConfig() *Config { GoGetWorkers: 10, ProtocolWorkers: 30, LogLevel: "debug", - LogFormat: "json", + LogFormat: "plain", CloudRuntime: "none", EnablePprof: false, PprofPort: ":3001", diff --git a/pkg/config/config_test.go b/pkg/config/config_test.go index fe3a7425..e10a2afb 100644 --- a/pkg/config/config_test.go +++ b/pkg/config/config_test.go @@ -258,7 +258,7 @@ func TestParseExampleConfig(t *testing.T) { expConf := &Config{ GoEnv: "development", LogLevel: "debug", - LogFormat: "json", + LogFormat: "plain", GoBinary: "go", GoGetWorkers: 10, ProtocolWorkers: 30, diff --git a/pkg/log/format.go b/pkg/log/format.go index bbddce44..4db34ae1 100644 --- a/pkg/log/format.go +++ b/pkg/log/format.go @@ -65,9 +65,9 @@ func sortFields(data logrus.Fields) []string { } func parseFormat(format string) logrus.Formatter { - if format == "plain" { - return &logrus.TextFormatter{} + if format == "json" { + return &logrus.JSONFormatter{} } - return &logrus.JSONFormatter{} + return getDevFormatter() } diff --git a/pkg/log/log.go b/pkg/log/log.go index d70d4bfc..8013d4b7 100644 --- a/pkg/log/log.go +++ b/pkg/log/log.go @@ -19,8 +19,6 @@ func New(cloudProvider string, level logrus.Level, format string) *Logger { switch cloudProvider { case "GCP": l.Formatter = getGCPFormatter() - case "none": - l.Formatter = getDevFormatter() default: l.Formatter = parseFormat(format) } diff --git a/pkg/log/log_test.go b/pkg/log/log_test.go index 2fe57998..2639c7a1 100644 --- a/pkg/log/log_test.go +++ b/pkg/log/log_test.go @@ -83,10 +83,36 @@ var testCases = []input{ output: `{"message":"warn message","severity":"warning","timestamp":"%v"}` + "\n", }, { - name: "default json", - format: "json", - level: logrus.DebugLevel, - fields: logrus.Fields{"xyz": "abc", "abc": "xyz"}, + name: "default plain", + format: "plain", + cloudProvider: "none", + level: logrus.DebugLevel, + fields: logrus.Fields{"xyz": "abc", "abc": "xyz"}, + logFunc: func(e Entry) time.Time { + t := time.Now() + e.Warnf("warn message") + return t + }, + output: `WARNING[%v]: warn message` + "\t" + `abc=xyz xyz=abc` + " \n", + }, + { + name: "default", + cloudProvider: "none", + level: logrus.DebugLevel, + fields: logrus.Fields{"xyz": "abc", "abc": "xyz"}, + logFunc: func(e Entry) time.Time { + t := time.Now() + e.Warnf("warn message") + return t + }, + output: `WARNING[%v]: warn message` + "\t" + `abc=xyz xyz=abc` + " \n", + }, + { + name: "default json", + format: "json", + cloudProvider: "none", + level: logrus.DebugLevel, + fields: logrus.Fields{"xyz": "abc", "abc": "xyz"}, logFunc: func(e Entry) time.Time { t := time.Now() e.Warnf("warn message") @@ -99,7 +125,7 @@ var testCases = []input{ func TestCloudLogger(t *testing.T) { for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { - lggr := New(tc.cloudProvider, tc.level, "") + lggr := New(tc.cloudProvider, tc.level, tc.format) var buf bytes.Buffer lggr.Out = &buf e := lggr.WithFields(tc.fields) @@ -107,7 +133,11 @@ func TestCloudLogger(t *testing.T) { out := buf.String() expected := tc.output if strings.Contains(expected, "%v") { - expected = fmt.Sprintf(expected, entryTime.Format(time.RFC3339)) + if tc.format == "plain" || (tc.format == "" && (tc.cloudProvider == "none" || tc.cloudProvider == "")) { + expected = fmt.Sprintf(expected, entryTime.Format(time.Kitchen)) + } else { + expected = fmt.Sprintf(expected, entryTime.Format(time.RFC3339)) + } } require.Equal(t, expected, out, "expected the logged entry to match the testCase output")