Skip to content

Commit

Permalink
Fix ld logging config (#202)
Browse files Browse the repository at this point in the history
  • Loading branch information
mraerino authored Dec 16, 2020
1 parent 5b0dd71 commit 5922870
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
4 changes: 2 additions & 2 deletions featureflag/featureflag.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func NewClient(cfg *Config, logger logrus.FieldLogger) (Client, error) {
config.SendEvents = false
}

configureLogger(config.Loggers, logger)
configureLogger(&config.Loggers, logger)

if cfg.RelayHost != "" {
config.BaseUri = cfg.RelayHost
Expand Down Expand Up @@ -98,7 +98,7 @@ func (c *ldClient) AllEnabledFlags(key string) []string {
return flags
}

func configureLogger(ldLogger ldlog.Loggers, log logrus.FieldLogger) {
func configureLogger(ldLogger *ldlog.Loggers, log logrus.FieldLogger) {
if log == nil {
l := logrus.New()
l.SetOutput(ioutil.Discard)
Expand Down
19 changes: 19 additions & 0 deletions featureflag/featureflag_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package featureflag

import (
"bytes"
"testing"
"time"

"github.com/sirupsen/logrus"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"gopkg.in/launchdarkly/go-server-sdk.v4/ldfiledata"
)
Expand Down Expand Up @@ -56,3 +59,19 @@ func TestAllEnabledFlags(t *testing.T) {

require.Equal(t, []string{"my-boolean-flag-key"}, flags)
}

func TestLogging(t *testing.T) {
cfg := Config{
Key: "ABCD",
RequestTimeout: time.Second,
Enabled: false,
}

logBuf := new(bytes.Buffer)
log := logrus.New()
log.Out = logBuf

_, err := NewClient(&cfg, log.WithField("component", "launch_darkly"))
require.NoError(t, err)
assert.NotEmpty(t, logBuf.Bytes())
}

0 comments on commit 5922870

Please sign in to comment.