Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add ability to set up log output #1602

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ data:
{{- else }}
format: text
{{- end }}
output: {{ .Values.global.logging.output }}
rpc: {{ .Values.global.logging.rpc.enabled }}
# Open Match applies the exponential backoff strategy for its retryable gRPC calls.
# The settings below are the default backoff configuration used in Open Match.
Expand Down
1 change: 1 addition & 0 deletions install/helm/open-match/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ global:
mountPath: /app/secrets/tls/rootca

logging:
output:
rpc:
enabled: false

Expand Down
14 changes: 14 additions & 0 deletions internal/logging/logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
package logging

import (
"log"
"os"
"strings"

stackdriver "github.com/TV4/logrus-stackdriver-formatter"
Expand All @@ -27,6 +29,7 @@ import (
// - log line format (text[default] or json)
// - min log level to include (debug, info [default], warn, error, fatal, panic)
func ConfigureLogging(cfg config.View) {
log.SetOutput(toOutput(cfg.GetString("logging.output")))
logrus.SetFormatter(newFormatter(cfg.GetString("logging.format")))
level := toLevel(cfg.GetString("logging.level"))
logrus.SetLevel(level)
Expand Down Expand Up @@ -84,3 +87,14 @@ func isDebugLevel(level logrus.Level) bool {
}
return false
}

func toOutput(output string) *os.File {
switch output {
case "stdout":
return os.Stdout
case "stderr":
return os.Stderr
default:
return os.Stderr
}
}
20 changes: 20 additions & 0 deletions internal/logging/logging_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package logging

import (
"fmt"
"os"
"reflect"
"testing"

Expand Down Expand Up @@ -93,3 +94,22 @@ func TestToLevel(t *testing.T) {
})
}
}

func TestToOutput(t *testing.T) {
testCases := []struct {
in string
expected *os.File
}{
{"stdout", os.Stdout},
{"stderr", os.Stderr},
{"", os.Stderr},
}
for _, tc := range testCases {
tc := tc
t.Run(fmt.Sprintf("toOutput(%s) => %s", tc.in, tc.expected.Name()), func(t *testing.T) {
require := require.New(t)
actual := toOutput(tc.in)
require.Equal(tc.expected, actual)
})
}
}