Skip to content

Commit

Permalink
Use plain logger as default
Browse files Browse the repository at this point in the history
  • Loading branch information
matt0x6F committed Mar 25, 2024
1 parent d080542 commit a303dd5
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 4 deletions.
2 changes: 1 addition & 1 deletion config.dev.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ func defaultConfig() *Config {
GoGetWorkers: 10,
ProtocolWorkers: 30,
LogLevel: "debug",
LogFormat: "json",
LogFormat: "plain",
CloudRuntime: "none",
EnablePprof: false,
PprofPort: ":3001",
Expand Down
2 changes: 1 addition & 1 deletion pkg/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
14 changes: 13 additions & 1 deletion pkg/log/log_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,18 @@ var testCases = []input{
},
{
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,
Expand All @@ -121,7 +133,7 @@ func TestCloudLogger(t *testing.T) {
out := buf.String()
expected := tc.output
if strings.Contains(expected, "%v") {
if tc.format == "plain" {
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))
Expand Down

0 comments on commit a303dd5

Please sign in to comment.