Remove the logrus logger wrapper
This commit is contained in:
parent
aec2edb441
commit
06521ffa49
@ -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 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,
|
Out: os.Stderr,
|
||||||
Formatter: &formatter,
|
Formatter: &formatter,
|
||||||
Level: logLevel,
|
Level: logLevel,
|
||||||
}), nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,6 @@ import (
|
|||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
|
|
||||||
"github.com/dexidp/dex/connector"
|
"github.com/dexidp/dex/connector"
|
||||||
"github.com/dexidp/dex/pkg/log"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const envVar = "DEX_LDAP_TESTS"
|
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.BindDN = "cn=admin,dc=example,dc=org"
|
||||||
c.BindPW = "admin"
|
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)
|
conn, err := c.openConnector(l)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -5,7 +5,6 @@ import (
|
|||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"encoding/pem"
|
"encoding/pem"
|
||||||
"errors"
|
"errors"
|
||||||
"github.com/dexidp/dex/pkg/log"
|
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"sort"
|
"sort"
|
||||||
"testing"
|
"testing"
|
||||||
@ -305,7 +304,7 @@ func (r responseTest) run(t *testing.T) {
|
|||||||
t.Fatalf("parse test time: %v", err)
|
t.Fatalf("parse test time: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
conn, err := c.openConnector(log.NewLogrusLogger(logrus.New()))
|
conn, err := c.openConnector(logrus.New())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@ -339,7 +338,7 @@ func (r responseTest) run(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestConfigCAData(t *testing.T) {
|
func TestConfigCAData(t *testing.T) {
|
||||||
logger := log.NewLogrusLogger(logrus.New())
|
logger := logrus.New()
|
||||||
validPEM, err := ioutil.ReadFile("testdata/ca.crt")
|
validPEM, err := ioutil.ReadFile("testdata/ca.crt")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
@ -476,7 +475,7 @@ func newProvider(ssoIssuer string, redirectURI string) *provider {
|
|||||||
usernameAttr: "user",
|
usernameAttr: "user",
|
||||||
emailAttr: "email",
|
emailAttr: "email",
|
||||||
redirectURI: redirectURI,
|
redirectURI: redirectURI,
|
||||||
logger: log.NewLogrusLogger(logrus.New()),
|
logger: logrus.New(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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...)
|
|
||||||
}
|
|
@ -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)
|
|
||||||
}
|
|
||||||
}
|
|
@ -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
|
// Attempts to create, update and delete a test Password
|
||||||
func TestPassword(t *testing.T) {
|
func TestPassword(t *testing.T) {
|
||||||
logger := log.NewLogrusLogger(&logrus.Logger{
|
logger := &logrus.Logger{
|
||||||
Out: os.Stderr,
|
Out: os.Stderr,
|
||||||
Formatter: &logrus.TextFormatter{DisableColors: true},
|
Formatter: &logrus.TextFormatter{DisableColors: true},
|
||||||
Level: logrus.DebugLevel,
|
Level: logrus.DebugLevel,
|
||||||
})
|
}
|
||||||
|
|
||||||
s := memory.New(logger)
|
s := memory.New(logger)
|
||||||
client := newAPI(s, logger, t)
|
client := newAPI(s, logger, t)
|
||||||
@ -123,11 +123,11 @@ func TestPassword(t *testing.T) {
|
|||||||
|
|
||||||
// Ensures checkCost returns expected values
|
// Ensures checkCost returns expected values
|
||||||
func TestCheckCost(t *testing.T) {
|
func TestCheckCost(t *testing.T) {
|
||||||
logger := log.NewLogrusLogger(&logrus.Logger{
|
logger := &logrus.Logger{
|
||||||
Out: os.Stderr,
|
Out: os.Stderr,
|
||||||
Formatter: &logrus.TextFormatter{DisableColors: true},
|
Formatter: &logrus.TextFormatter{DisableColors: true},
|
||||||
Level: logrus.DebugLevel,
|
Level: logrus.DebugLevel,
|
||||||
})
|
}
|
||||||
|
|
||||||
s := memory.New(logger)
|
s := memory.New(logger)
|
||||||
client := newAPI(s, logger, t)
|
client := newAPI(s, logger, t)
|
||||||
@ -180,11 +180,11 @@ func TestCheckCost(t *testing.T) {
|
|||||||
|
|
||||||
// Attempts to list and revoke an exisiting refresh token.
|
// Attempts to list and revoke an exisiting refresh token.
|
||||||
func TestRefreshToken(t *testing.T) {
|
func TestRefreshToken(t *testing.T) {
|
||||||
logger := log.NewLogrusLogger(&logrus.Logger{
|
logger := &logrus.Logger{
|
||||||
Out: os.Stderr,
|
Out: os.Stderr,
|
||||||
Formatter: &logrus.TextFormatter{DisableColors: true},
|
Formatter: &logrus.TextFormatter{DisableColors: true},
|
||||||
Level: logrus.DebugLevel,
|
Level: logrus.DebugLevel,
|
||||||
})
|
}
|
||||||
|
|
||||||
s := memory.New(logger)
|
s := memory.New(logger)
|
||||||
client := newAPI(s, logger, t)
|
client := newAPI(s, logger, t)
|
||||||
@ -293,11 +293,11 @@ func TestRefreshToken(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestUpdateClient(t *testing.T) {
|
func TestUpdateClient(t *testing.T) {
|
||||||
logger := log.NewLogrusLogger(&logrus.Logger{
|
logger := &logrus.Logger{
|
||||||
Out: os.Stderr,
|
Out: os.Stderr,
|
||||||
Formatter: &logrus.TextFormatter{DisableColors: true},
|
Formatter: &logrus.TextFormatter{DisableColors: true},
|
||||||
Level: logrus.DebugLevel,
|
Level: logrus.DebugLevel,
|
||||||
})
|
}
|
||||||
|
|
||||||
s := memory.New(logger)
|
s := memory.New(logger)
|
||||||
client := newAPI(s, logger, t)
|
client := newAPI(s, logger, t)
|
||||||
|
@ -8,7 +8,6 @@ import (
|
|||||||
|
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
|
|
||||||
"github.com/dexidp/dex/pkg/log"
|
|
||||||
"github.com/dexidp/dex/storage"
|
"github.com/dexidp/dex/storage"
|
||||||
"github.com/dexidp/dex/storage/memory"
|
"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.
|
// Only the last 5 verification keys are expected to be kept around.
|
||||||
maxVerificationKeys := 5
|
maxVerificationKeys := 5
|
||||||
|
|
||||||
l := log.NewLogrusLogger(&logrus.Logger{
|
l := &logrus.Logger{
|
||||||
Out: os.Stderr,
|
Out: os.Stderr,
|
||||||
Formatter: &logrus.TextFormatter{DisableColors: true},
|
Formatter: &logrus.TextFormatter{DisableColors: true},
|
||||||
Level: logrus.DebugLevel,
|
Level: logrus.DebugLevel,
|
||||||
})
|
}
|
||||||
|
|
||||||
r := &keyRotater{
|
r := &keyRotater{
|
||||||
Storage: memory.New(l),
|
Storage: memory.New(l),
|
||||||
|
@ -30,7 +30,6 @@ import (
|
|||||||
|
|
||||||
"github.com/dexidp/dex/connector"
|
"github.com/dexidp/dex/connector"
|
||||||
"github.com/dexidp/dex/connector/mock"
|
"github.com/dexidp/dex/connector/mock"
|
||||||
"github.com/dexidp/dex/pkg/log"
|
|
||||||
"github.com/dexidp/dex/storage"
|
"github.com/dexidp/dex/storage"
|
||||||
"github.com/dexidp/dex/storage/memory"
|
"github.com/dexidp/dex/storage/memory"
|
||||||
)
|
)
|
||||||
@ -75,11 +74,11 @@ FDWV28nTP9sqbtsmU8Tem2jzMvZ7C/Q0AuDoKELFUpux8shm8wfIhyaPnXUGZoAZ
|
|||||||
Np4vUwMSYV5mopESLWOg3loBxKyLGFtgGKVCjGiQvy6zISQ4fQo=
|
Np4vUwMSYV5mopESLWOg3loBxKyLGFtgGKVCjGiQvy6zISQ4fQo=
|
||||||
-----END RSA PRIVATE KEY-----`)
|
-----END RSA PRIVATE KEY-----`)
|
||||||
|
|
||||||
var logger = log.NewLogrusLogger(&logrus.Logger{
|
var logger = &logrus.Logger{
|
||||||
Out: os.Stderr,
|
Out: os.Stderr,
|
||||||
Formatter: &logrus.TextFormatter{DisableColors: true},
|
Formatter: &logrus.TextFormatter{DisableColors: true},
|
||||||
Level: logrus.DebugLevel,
|
Level: logrus.DebugLevel,
|
||||||
})
|
}
|
||||||
|
|
||||||
func newTestServer(ctx context.Context, t *testing.T, updateConfig func(c *Config)) (*httptest.Server, *Server) {
|
func newTestServer(ctx context.Context, t *testing.T, updateConfig func(c *Config)) (*httptest.Server, *Server) {
|
||||||
var server *Server
|
var server *Server
|
||||||
|
@ -3,7 +3,6 @@ package etcd
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/dexidp/dex/pkg/log"
|
|
||||||
"os"
|
"os"
|
||||||
"runtime"
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
@ -54,11 +53,11 @@ func cleanDB(c *conn) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var logger = log.NewLogrusLogger(&logrus.Logger{
|
var logger = &logrus.Logger{
|
||||||
Out: os.Stderr,
|
Out: os.Stderr,
|
||||||
Formatter: &logrus.TextFormatter{DisableColors: true},
|
Formatter: &logrus.TextFormatter{DisableColors: true},
|
||||||
Level: logrus.DebugLevel,
|
Level: logrus.DebugLevel,
|
||||||
})
|
}
|
||||||
|
|
||||||
func TestEtcd(t *testing.T) {
|
func TestEtcd(t *testing.T) {
|
||||||
testEtcdEnv := "DEX_ETCD_ENDPOINTS"
|
testEtcdEnv := "DEX_ETCD_ENDPOINTS"
|
||||||
|
@ -7,7 +7,6 @@ import (
|
|||||||
|
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
|
|
||||||
"github.com/dexidp/dex/pkg/log"
|
|
||||||
"github.com/dexidp/dex/storage"
|
"github.com/dexidp/dex/storage"
|
||||||
"github.com/dexidp/dex/storage/conformance"
|
"github.com/dexidp/dex/storage/conformance"
|
||||||
)
|
)
|
||||||
@ -25,11 +24,11 @@ func loadClient(t *testing.T) *client {
|
|||||||
if config.KubeConfigFile == "" {
|
if config.KubeConfigFile == "" {
|
||||||
t.Skipf("test environment variable %q not set, skipping", testKubeConfigEnv)
|
t.Skipf("test environment variable %q not set, skipping", testKubeConfigEnv)
|
||||||
}
|
}
|
||||||
logger := log.NewLogrusLogger(&logrus.Logger{
|
logger := &logrus.Logger{
|
||||||
Out: os.Stderr,
|
Out: os.Stderr,
|
||||||
Formatter: &logrus.TextFormatter{DisableColors: true},
|
Formatter: &logrus.TextFormatter{DisableColors: true},
|
||||||
Level: logrus.DebugLevel,
|
Level: logrus.DebugLevel,
|
||||||
})
|
}
|
||||||
s, err := config.open(logger, true)
|
s, err := config.open(logger, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
|
@ -6,17 +6,16 @@ import (
|
|||||||
|
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
|
|
||||||
"github.com/dexidp/dex/pkg/log"
|
|
||||||
"github.com/dexidp/dex/storage"
|
"github.com/dexidp/dex/storage"
|
||||||
"github.com/dexidp/dex/storage/conformance"
|
"github.com/dexidp/dex/storage/conformance"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestStorage(t *testing.T) {
|
func TestStorage(t *testing.T) {
|
||||||
logger := log.NewLogrusLogger(&logrus.Logger{
|
logger := &logrus.Logger{
|
||||||
Out: os.Stderr,
|
Out: os.Stderr,
|
||||||
Formatter: &logrus.TextFormatter{DisableColors: true},
|
Formatter: &logrus.TextFormatter{DisableColors: true},
|
||||||
Level: logrus.DebugLevel,
|
Level: logrus.DebugLevel,
|
||||||
})
|
}
|
||||||
|
|
||||||
newStorage := func() storage.Storage {
|
newStorage := func() storage.Storage {
|
||||||
return New(logger)
|
return New(logger)
|
||||||
|
@ -8,16 +8,15 @@ import (
|
|||||||
|
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
|
|
||||||
"github.com/dexidp/dex/pkg/log"
|
|
||||||
"github.com/dexidp/dex/storage"
|
"github.com/dexidp/dex/storage"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestStaticClients(t *testing.T) {
|
func TestStaticClients(t *testing.T) {
|
||||||
logger := log.NewLogrusLogger(&logrus.Logger{
|
logger := &logrus.Logger{
|
||||||
Out: os.Stderr,
|
Out: os.Stderr,
|
||||||
Formatter: &logrus.TextFormatter{DisableColors: true},
|
Formatter: &logrus.TextFormatter{DisableColors: true},
|
||||||
Level: logrus.DebugLevel,
|
Level: logrus.DebugLevel,
|
||||||
})
|
}
|
||||||
backing := New(logger)
|
backing := New(logger)
|
||||||
|
|
||||||
c1 := storage.Client{ID: "foo", Secret: "foo_secret"}
|
c1 := storage.Client{ID: "foo", Secret: "foo_secret"}
|
||||||
@ -100,11 +99,11 @@ func TestStaticClients(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestStaticPasswords(t *testing.T) {
|
func TestStaticPasswords(t *testing.T) {
|
||||||
logger := log.NewLogrusLogger(&logrus.Logger{
|
logger := &logrus.Logger{
|
||||||
Out: os.Stderr,
|
Out: os.Stderr,
|
||||||
Formatter: &logrus.TextFormatter{DisableColors: true},
|
Formatter: &logrus.TextFormatter{DisableColors: true},
|
||||||
Level: logrus.DebugLevel,
|
Level: logrus.DebugLevel,
|
||||||
})
|
}
|
||||||
backing := New(logger)
|
backing := New(logger)
|
||||||
|
|
||||||
p1 := storage.Password{Email: "foo@example.com", Username: "foo_secret"}
|
p1 := storage.Password{Email: "foo@example.com", Username: "foo_secret"}
|
||||||
@ -212,11 +211,11 @@ func TestStaticPasswords(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestStaticConnectors(t *testing.T) {
|
func TestStaticConnectors(t *testing.T) {
|
||||||
logger := log.NewLogrusLogger(&logrus.Logger{
|
logger := &logrus.Logger{
|
||||||
Out: os.Stderr,
|
Out: os.Stderr,
|
||||||
Formatter: &logrus.TextFormatter{DisableColors: true},
|
Formatter: &logrus.TextFormatter{DisableColors: true},
|
||||||
Level: logrus.DebugLevel,
|
Level: logrus.DebugLevel,
|
||||||
})
|
}
|
||||||
backing := New(logger)
|
backing := New(logger)
|
||||||
|
|
||||||
config1 := []byte(`{"issuer": "https://accounts.google.com"}`)
|
config1 := []byte(`{"issuer": "https://accounts.google.com"}`)
|
||||||
|
@ -9,7 +9,6 @@ import (
|
|||||||
|
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
|
|
||||||
"github.com/dexidp/dex/pkg/log"
|
|
||||||
"github.com/dexidp/dex/storage"
|
"github.com/dexidp/dex/storage"
|
||||||
"github.com/dexidp/dex/storage/conformance"
|
"github.com/dexidp/dex/storage/conformance"
|
||||||
)
|
)
|
||||||
@ -44,11 +43,11 @@ func cleanDB(c *conn) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
var logger = log.NewLogrusLogger(&logrus.Logger{
|
var logger = &logrus.Logger{
|
||||||
Out: os.Stderr,
|
Out: os.Stderr,
|
||||||
Formatter: &logrus.TextFormatter{DisableColors: true},
|
Formatter: &logrus.TextFormatter{DisableColors: true},
|
||||||
Level: logrus.DebugLevel,
|
Level: logrus.DebugLevel,
|
||||||
})
|
}
|
||||||
|
|
||||||
func TestSQLite3(t *testing.T) {
|
func TestSQLite3(t *testing.T) {
|
||||||
newStorage := func() storage.Storage {
|
newStorage := func() storage.Storage {
|
||||||
|
@ -7,8 +7,6 @@ import (
|
|||||||
|
|
||||||
sqlite3 "github.com/mattn/go-sqlite3"
|
sqlite3 "github.com/mattn/go-sqlite3"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
|
|
||||||
"github.com/dexidp/dex/pkg/log"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestMigrate(t *testing.T) {
|
func TestMigrate(t *testing.T) {
|
||||||
@ -18,11 +16,11 @@ func TestMigrate(t *testing.T) {
|
|||||||
}
|
}
|
||||||
defer db.Close()
|
defer db.Close()
|
||||||
|
|
||||||
logger := log.NewLogrusLogger(&logrus.Logger{
|
logger := &logrus.Logger{
|
||||||
Out: os.Stderr,
|
Out: os.Stderr,
|
||||||
Formatter: &logrus.TextFormatter{DisableColors: true},
|
Formatter: &logrus.TextFormatter{DisableColors: true},
|
||||||
Level: logrus.DebugLevel,
|
Level: logrus.DebugLevel,
|
||||||
})
|
}
|
||||||
|
|
||||||
errCheck := func(err error) bool {
|
errCheck := func(err error) bool {
|
||||||
sqlErr, ok := err.(sqlite3.Error)
|
sqlErr, ok := err.(sqlite3.Error)
|
||||||
|
Reference in New Issue
Block a user