From 06521ffa49b6d7ea81a756f1e297abd4ec39a071 Mon Sep 17 00:00:00 2001 From: Mark Sagi-Kazar Date: Fri, 22 Feb 2019 21:31:46 +0100 Subject: [PATCH] Remove the logrus logger wrapper --- cmd/dex/serve.go | 4 +-- connector/ldap/ldap_test.go | 3 +-- connector/saml/saml_test.go | 7 +++--- pkg/log/logrus.go | 40 ------------------------------ pkg/log/logrus_test.go | 10 -------- server/api_test.go | 16 ++++++------ server/rotation_test.go | 5 ++-- server/server_test.go | 5 ++-- storage/etcd/etcd_test.go | 5 ++-- storage/kubernetes/storage_test.go | 5 ++-- storage/memory/memory_test.go | 5 ++-- storage/memory/static_test.go | 13 +++++----- storage/sql/config_test.go | 5 ++-- storage/sql/migrate_test.go | 6 ++--- 14 files changed, 34 insertions(+), 95 deletions(-) delete mode 100644 pkg/log/logrus.go delete mode 100644 pkg/log/logrus_test.go diff --git a/cmd/dex/serve.go b/cmd/dex/serve.go index 0933eb4f..8ebaaea0 100644 --- a/cmd/dex/serve.go +++ b/cmd/dex/serve.go @@ -348,9 +348,9 @@ func newLogger(level string, format string) (log.Logger, error) { return nil, fmt.Errorf("log format is not one of the supported values (%s): %s", strings.Join(logFormats, ", "), format) } - return log.NewLogrusLogger(&logrus.Logger{ + return &logrus.Logger{ Out: os.Stderr, Formatter: &formatter, Level: logLevel, - }), nil + }, nil } diff --git a/connector/ldap/ldap_test.go b/connector/ldap/ldap_test.go index c6f30807..fa6b7062 100644 --- a/connector/ldap/ldap_test.go +++ b/connector/ldap/ldap_test.go @@ -17,7 +17,6 @@ import ( "github.com/sirupsen/logrus" "github.com/dexidp/dex/connector" - "github.com/dexidp/dex/pkg/log" ) const envVar = "DEX_LDAP_TESTS" @@ -876,7 +875,7 @@ func runTests(t *testing.T, schema string, connMethod connectionMethod, config * c.BindDN = "cn=admin,dc=example,dc=org" c.BindPW = "admin" - l := log.NewLogrusLogger(&logrus.Logger{Out: ioutil.Discard, Formatter: &logrus.TextFormatter{}}) + l := &logrus.Logger{Out: ioutil.Discard, Formatter: &logrus.TextFormatter{}} conn, err := c.openConnector(l) if err != nil { diff --git a/connector/saml/saml_test.go b/connector/saml/saml_test.go index e7ccbbb8..4497d059 100644 --- a/connector/saml/saml_test.go +++ b/connector/saml/saml_test.go @@ -5,7 +5,6 @@ import ( "encoding/base64" "encoding/pem" "errors" - "github.com/dexidp/dex/pkg/log" "io/ioutil" "sort" "testing" @@ -305,7 +304,7 @@ func (r responseTest) run(t *testing.T) { t.Fatalf("parse test time: %v", err) } - conn, err := c.openConnector(log.NewLogrusLogger(logrus.New())) + conn, err := c.openConnector(logrus.New()) if err != nil { t.Fatal(err) } @@ -339,7 +338,7 @@ func (r responseTest) run(t *testing.T) { } func TestConfigCAData(t *testing.T) { - logger := log.NewLogrusLogger(logrus.New()) + logger := logrus.New() validPEM, err := ioutil.ReadFile("testdata/ca.crt") if err != nil { t.Fatal(err) @@ -476,7 +475,7 @@ func newProvider(ssoIssuer string, redirectURI string) *provider { usernameAttr: "user", emailAttr: "email", redirectURI: redirectURI, - logger: log.NewLogrusLogger(logrus.New()), + logger: logrus.New(), } } diff --git a/pkg/log/logrus.go b/pkg/log/logrus.go deleted file mode 100644 index 839f79e6..00000000 --- a/pkg/log/logrus.go +++ /dev/null @@ -1,40 +0,0 @@ -package log - -import "github.com/sirupsen/logrus" - -// LogrusLogger is an adapter for Logrus implementing the Logger interface. -type LogrusLogger struct { - logger logrus.FieldLogger -} - -// NewLogrusLogger returns a new Logger wrapping Logrus. -func NewLogrusLogger(logger logrus.FieldLogger) *LogrusLogger { - return &LogrusLogger{ - logger: logger, - } -} - -// Info logs an Info level event. -func (l *LogrusLogger) Info(args ...interface{}) { - l.logger.Info(args...) -} - -// Warn logs a Warn level event. -func (l *LogrusLogger) Warn(args ...interface{}) { - l.logger.Warn(args...) -} - -// Debugf formats and logs a Debug level event. -func (l *LogrusLogger) Debugf(format string, args ...interface{}) { - l.logger.Debugf(format, args...) -} - -// Infof formats and logs an Info level event. -func (l *LogrusLogger) Infof(format string, args ...interface{}) { - l.logger.Infof(format, args...) -} - -// Errorf formats and logs n Error level event. -func (l *LogrusLogger) Errorf(format string, args ...interface{}) { - l.logger.Errorf(format, args...) -} diff --git a/pkg/log/logrus_test.go b/pkg/log/logrus_test.go deleted file mode 100644 index cb60c6b9..00000000 --- a/pkg/log/logrus_test.go +++ /dev/null @@ -1,10 +0,0 @@ -package log - -import "testing" - -func TestLogrusLoggerImplementsLoggerInterface(t *testing.T) { - var i interface{} = new(LogrusLogger) - if _, ok := i.(Logger); !ok { - t.Errorf("expected %T to implement Logger interface", i) - } -} diff --git a/server/api_test.go b/server/api_test.go index dbd67b0a..568748bf 100644 --- a/server/api_test.go +++ b/server/api_test.go @@ -58,11 +58,11 @@ func newAPI(s storage.Storage, logger log.Logger, t *testing.T) *apiClient { // Attempts to create, update and delete a test Password func TestPassword(t *testing.T) { - logger := log.NewLogrusLogger(&logrus.Logger{ + logger := &logrus.Logger{ Out: os.Stderr, Formatter: &logrus.TextFormatter{DisableColors: true}, Level: logrus.DebugLevel, - }) + } s := memory.New(logger) client := newAPI(s, logger, t) @@ -123,11 +123,11 @@ func TestPassword(t *testing.T) { // Ensures checkCost returns expected values func TestCheckCost(t *testing.T) { - logger := log.NewLogrusLogger(&logrus.Logger{ + logger := &logrus.Logger{ Out: os.Stderr, Formatter: &logrus.TextFormatter{DisableColors: true}, Level: logrus.DebugLevel, - }) + } s := memory.New(logger) client := newAPI(s, logger, t) @@ -180,11 +180,11 @@ func TestCheckCost(t *testing.T) { // Attempts to list and revoke an exisiting refresh token. func TestRefreshToken(t *testing.T) { - logger := log.NewLogrusLogger(&logrus.Logger{ + logger := &logrus.Logger{ Out: os.Stderr, Formatter: &logrus.TextFormatter{DisableColors: true}, Level: logrus.DebugLevel, - }) + } s := memory.New(logger) client := newAPI(s, logger, t) @@ -293,11 +293,11 @@ func TestRefreshToken(t *testing.T) { } func TestUpdateClient(t *testing.T) { - logger := log.NewLogrusLogger(&logrus.Logger{ + logger := &logrus.Logger{ Out: os.Stderr, Formatter: &logrus.TextFormatter{DisableColors: true}, Level: logrus.DebugLevel, - }) + } s := memory.New(logger) client := newAPI(s, logger, t) diff --git a/server/rotation_test.go b/server/rotation_test.go index f77ec783..66c269ce 100644 --- a/server/rotation_test.go +++ b/server/rotation_test.go @@ -8,7 +8,6 @@ import ( "github.com/sirupsen/logrus" - "github.com/dexidp/dex/pkg/log" "github.com/dexidp/dex/storage" "github.com/dexidp/dex/storage/memory" ) @@ -68,11 +67,11 @@ func TestKeyRotater(t *testing.T) { // Only the last 5 verification keys are expected to be kept around. maxVerificationKeys := 5 - l := log.NewLogrusLogger(&logrus.Logger{ + l := &logrus.Logger{ Out: os.Stderr, Formatter: &logrus.TextFormatter{DisableColors: true}, Level: logrus.DebugLevel, - }) + } r := &keyRotater{ Storage: memory.New(l), diff --git a/server/server_test.go b/server/server_test.go index 1433162b..536387c4 100644 --- a/server/server_test.go +++ b/server/server_test.go @@ -30,7 +30,6 @@ import ( "github.com/dexidp/dex/connector" "github.com/dexidp/dex/connector/mock" - "github.com/dexidp/dex/pkg/log" "github.com/dexidp/dex/storage" "github.com/dexidp/dex/storage/memory" ) @@ -75,11 +74,11 @@ FDWV28nTP9sqbtsmU8Tem2jzMvZ7C/Q0AuDoKELFUpux8shm8wfIhyaPnXUGZoAZ Np4vUwMSYV5mopESLWOg3loBxKyLGFtgGKVCjGiQvy6zISQ4fQo= -----END RSA PRIVATE KEY-----`) -var logger = log.NewLogrusLogger(&logrus.Logger{ +var logger = &logrus.Logger{ Out: os.Stderr, Formatter: &logrus.TextFormatter{DisableColors: true}, Level: logrus.DebugLevel, -}) +} func newTestServer(ctx context.Context, t *testing.T, updateConfig func(c *Config)) (*httptest.Server, *Server) { var server *Server diff --git a/storage/etcd/etcd_test.go b/storage/etcd/etcd_test.go index ac5ab175..bd412536 100644 --- a/storage/etcd/etcd_test.go +++ b/storage/etcd/etcd_test.go @@ -3,7 +3,6 @@ package etcd import ( "context" "fmt" - "github.com/dexidp/dex/pkg/log" "os" "runtime" "strings" @@ -54,11 +53,11 @@ func cleanDB(c *conn) error { return nil } -var logger = log.NewLogrusLogger(&logrus.Logger{ +var logger = &logrus.Logger{ Out: os.Stderr, Formatter: &logrus.TextFormatter{DisableColors: true}, Level: logrus.DebugLevel, -}) +} func TestEtcd(t *testing.T) { testEtcdEnv := "DEX_ETCD_ENDPOINTS" diff --git a/storage/kubernetes/storage_test.go b/storage/kubernetes/storage_test.go index d6e4a1af..27d65416 100644 --- a/storage/kubernetes/storage_test.go +++ b/storage/kubernetes/storage_test.go @@ -7,7 +7,6 @@ import ( "github.com/sirupsen/logrus" - "github.com/dexidp/dex/pkg/log" "github.com/dexidp/dex/storage" "github.com/dexidp/dex/storage/conformance" ) @@ -25,11 +24,11 @@ func loadClient(t *testing.T) *client { if config.KubeConfigFile == "" { t.Skipf("test environment variable %q not set, skipping", testKubeConfigEnv) } - logger := log.NewLogrusLogger(&logrus.Logger{ + logger := &logrus.Logger{ Out: os.Stderr, Formatter: &logrus.TextFormatter{DisableColors: true}, Level: logrus.DebugLevel, - }) + } s, err := config.open(logger, true) if err != nil { t.Fatal(err) diff --git a/storage/memory/memory_test.go b/storage/memory/memory_test.go index 804bd6fe..84a8826e 100644 --- a/storage/memory/memory_test.go +++ b/storage/memory/memory_test.go @@ -6,17 +6,16 @@ import ( "github.com/sirupsen/logrus" - "github.com/dexidp/dex/pkg/log" "github.com/dexidp/dex/storage" "github.com/dexidp/dex/storage/conformance" ) func TestStorage(t *testing.T) { - logger := log.NewLogrusLogger(&logrus.Logger{ + logger := &logrus.Logger{ Out: os.Stderr, Formatter: &logrus.TextFormatter{DisableColors: true}, Level: logrus.DebugLevel, - }) + } newStorage := func() storage.Storage { return New(logger) diff --git a/storage/memory/static_test.go b/storage/memory/static_test.go index 8ef8b270..8513e0ee 100644 --- a/storage/memory/static_test.go +++ b/storage/memory/static_test.go @@ -8,16 +8,15 @@ import ( "github.com/sirupsen/logrus" - "github.com/dexidp/dex/pkg/log" "github.com/dexidp/dex/storage" ) func TestStaticClients(t *testing.T) { - logger := log.NewLogrusLogger(&logrus.Logger{ + logger := &logrus.Logger{ Out: os.Stderr, Formatter: &logrus.TextFormatter{DisableColors: true}, Level: logrus.DebugLevel, - }) + } backing := New(logger) c1 := storage.Client{ID: "foo", Secret: "foo_secret"} @@ -100,11 +99,11 @@ func TestStaticClients(t *testing.T) { } func TestStaticPasswords(t *testing.T) { - logger := log.NewLogrusLogger(&logrus.Logger{ + logger := &logrus.Logger{ Out: os.Stderr, Formatter: &logrus.TextFormatter{DisableColors: true}, Level: logrus.DebugLevel, - }) + } backing := New(logger) p1 := storage.Password{Email: "foo@example.com", Username: "foo_secret"} @@ -212,11 +211,11 @@ func TestStaticPasswords(t *testing.T) { } func TestStaticConnectors(t *testing.T) { - logger := log.NewLogrusLogger(&logrus.Logger{ + logger := &logrus.Logger{ Out: os.Stderr, Formatter: &logrus.TextFormatter{DisableColors: true}, Level: logrus.DebugLevel, - }) + } backing := New(logger) config1 := []byte(`{"issuer": "https://accounts.google.com"}`) diff --git a/storage/sql/config_test.go b/storage/sql/config_test.go index 6cb52d36..d823e099 100644 --- a/storage/sql/config_test.go +++ b/storage/sql/config_test.go @@ -9,7 +9,6 @@ import ( "github.com/sirupsen/logrus" - "github.com/dexidp/dex/pkg/log" "github.com/dexidp/dex/storage" "github.com/dexidp/dex/storage/conformance" ) @@ -44,11 +43,11 @@ func cleanDB(c *conn) error { return err } -var logger = log.NewLogrusLogger(&logrus.Logger{ +var logger = &logrus.Logger{ Out: os.Stderr, Formatter: &logrus.TextFormatter{DisableColors: true}, Level: logrus.DebugLevel, -}) +} func TestSQLite3(t *testing.T) { newStorage := func() storage.Storage { diff --git a/storage/sql/migrate_test.go b/storage/sql/migrate_test.go index d9bfa98a..e94e819f 100644 --- a/storage/sql/migrate_test.go +++ b/storage/sql/migrate_test.go @@ -7,8 +7,6 @@ import ( sqlite3 "github.com/mattn/go-sqlite3" "github.com/sirupsen/logrus" - - "github.com/dexidp/dex/pkg/log" ) func TestMigrate(t *testing.T) { @@ -18,11 +16,11 @@ func TestMigrate(t *testing.T) { } defer db.Close() - logger := log.NewLogrusLogger(&logrus.Logger{ + logger := &logrus.Logger{ Out: os.Stderr, Formatter: &logrus.TextFormatter{DisableColors: true}, Level: logrus.DebugLevel, - }) + } errCheck := func(err error) bool { sqlErr, ok := err.(sqlite3.Error)