Skip to content
Closed
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
8 changes: 8 additions & 0 deletions internal/logger/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const (
Verbose Level = iota
Debug
Error
none
)

type Log struct {
Expand All @@ -32,6 +33,13 @@ func New(debug bool) *Log {
}
}

func NewDisabled() *Log {
return &Log{
logger: log.New(os.Stderr, "", log.LstdFlags),
level: none,
}
}

func (l *Log) Verbose(format string, args ...interface{}) {
if l.level <= Verbose {
format = fmt.Sprintf("DEBUG - %v\n", format)
Expand Down
4 changes: 4 additions & 0 deletions pkg/experiment/local/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ func Initialize(apiKey string, config *Config) *Client {
}
config = fillConfigDefaults(config)
log := logger.New(config.Debug)
if config.DisableLogging {
log = logger.NewDisabled()
}

var as *assignmentService
if config.AssignmentConfig != nil && config.AssignmentConfig.APIKey != "" {
amplitudeClient := amplitude.NewClient(config.AssignmentConfig.Config)
Expand Down
1 change: 1 addition & 0 deletions pkg/experiment/local/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const (

type Config struct {
Debug bool
DisableLogging bool
ServerUrl string
ServerZone ServerZone
FlagConfigPollerInterval time.Duration
Expand Down
8 changes: 7 additions & 1 deletion pkg/experiment/remote/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,14 @@ func Initialize(apiKey string, config *Config) *Client {
panic("api key must be set")
}
config = fillConfigDefaults(config)

l := logger.New(config.Debug)
if config.DisableLogging {
l = logger.NewDisabled()
}

client = &Client{
log: logger.New(config.Debug),
log: l,
apiKey: apiKey,
config: config,
client: &http.Client{},
Expand Down
9 changes: 5 additions & 4 deletions pkg/experiment/remote/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ import (
)

type Config struct {
Debug bool
ServerUrl string
FetchTimeout time.Duration
RetryBackoff *RetryBackoff
Debug bool
DisableLogging bool
ServerUrl string
FetchTimeout time.Duration
RetryBackoff *RetryBackoff
}

var DefaultConfig = &Config{
Expand Down