diff --git a/featureflag/config.go b/featureflag/config.go index 2efffec..3c312d4 100644 --- a/featureflag/config.go +++ b/featureflag/config.go @@ -7,14 +7,15 @@ import ( ) type Config struct { - Key string - RequestTimeout time.Duration `mapstructure:"request_timeout" split_words:"true" default:"5s"` - Enabled bool `default:"false"` - updateProcessorFactory ld.UpdateProcessorFactory + Key string `json:"key" yaml:"key"` + RequestTimeout time.Duration `json:"request_timeout" yaml:"request_timeout" mapstructure:"request_timeout" split_words:"true" default:"5s"` + Enabled bool `json:"enabled" yaml:"enabled" default:"false"` + + updateProcessorFactory ld.UpdateProcessorFactory `json:"-"` // Drop telemetry events (not needed in local-dev/CI environments) - DisableEvents bool `mapstructure:"disable_events" split_words:"true"` + DisableEvents bool `json:"disable_events" yaml:"disable_events" mapstructure:"disable_events" split_words:"true"` // Set when using the Launch Darkly Relay proxy - RelayHost string `mapstructure:"relay_host" split_words:"true"` + RelayHost string `json:"relay_host" yaml:"relay_host" mapstructure:"relay_host" split_words:"true"` } diff --git a/featureflag/featureflag.go b/featureflag/featureflag.go index 9cb873b..9cb9d7e 100644 --- a/featureflag/featureflag.go +++ b/featureflag/featureflag.go @@ -6,6 +6,7 @@ import ( "github.com/sirupsen/logrus" ld "gopkg.in/launchdarkly/go-server-sdk.v4" + "gopkg.in/launchdarkly/go-server-sdk.v4/ldlog" ) type Client interface { @@ -37,7 +38,7 @@ func NewClient(cfg *Config, logger logrus.FieldLogger) (Client, error) { config.SendEvents = false } - config.Loggers.SetBaseLogger(wrapLogger(logger)) + configureLogger(config.Loggers, logger) if cfg.RelayHost != "" { config.BaseUri = cfg.RelayHost @@ -97,23 +98,29 @@ func (c *ldClient) AllEnabledFlags(key string) []string { return flags } -func wrapLogger(logger logrus.FieldLogger) infoToDebugLogger { - if logger == nil { +func configureLogger(ldLogger ldlog.Loggers, log logrus.FieldLogger) { + if log == nil { l := logrus.New() l.SetOutput(ioutil.Discard) - logger = l + log = l } + log = log.WithField("component", "launch_darkly") - return infoToDebugLogger{logger.WithField("component", "launch_darkly")} + ldLogger.SetBaseLoggerForLevel(ldlog.Debug, &wrapLog{log.Debugln, log.Debugf}) + ldLogger.SetBaseLoggerForLevel(ldlog.Info, &wrapLog{log.Infoln, log.Infof}) + ldLogger.SetBaseLoggerForLevel(ldlog.Warn, &wrapLog{log.Warnln, log.Warnf}) + ldLogger.SetBaseLoggerForLevel(ldlog.Error, &wrapLog{log.Errorln, log.Errorf}) } -type infoToDebugLogger struct { - log logrus.FieldLogger +type wrapLog struct { + println func(values ...interface{}) + printf func(format string, values ...interface{}) } -func (l infoToDebugLogger) Println(values ...interface{}) { - l.log.Debugln(values...) +func (l *wrapLog) Println(values ...interface{}) { + l.println(values...) } -func (l infoToDebugLogger) Printf(format string, values ...interface{}) { - l.log.Debugf(format, values...) + +func (l *wrapLog) Printf(format string, values ...interface{}) { + l.printf(format, values...) }