Skip to content

Commit

Permalink
disable error logging (#149)
Browse files Browse the repository at this point in the history
  • Loading branch information
kenny-statsig authored Jan 29, 2024
1 parent 0dc81eb commit 55ce0d8
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
5 changes: 5 additions & 0 deletions error_boundary.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ type errorBoundary struct {
seen map[string]bool
seenLock sync.RWMutex
diagnostics *diagnostics
options *Options
}

type logExceptionRequestBody struct {
Expand Down Expand Up @@ -47,6 +48,7 @@ func newErrorBoundary(sdkKey string, options *Options, diagnostics *diagnostics)
client: &http.Client{Timeout: time.Second * 3},
seen: make(map[string]bool),
diagnostics: diagnostics,
options: options,
}
if options.API != "" {
errorBoundary.api = options.API
Expand Down Expand Up @@ -113,6 +115,9 @@ func (e *errorBoundary) ebRecover(recoverCallback func()) {
}

func (e *errorBoundary) logException(exception error) {
if e.options.StatsigLoggerOptions.DisableAllLogging {
return
}
var exceptionString string
if exception == nil {
exceptionString = "Unknown"
Expand Down
5 changes: 4 additions & 1 deletion logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ type logger struct {
tick *time.Ticker
mu sync.Mutex
maxEvents int
disabled bool
diagnostics *diagnostics
options *Options
}
Expand All @@ -62,11 +63,13 @@ func newLogger(transport *transport, options *Options, diagnostics *diagnostics)
if options.LoggingMaxBufferSize > 0 {
maxEvents = options.LoggingMaxBufferSize
}
disabled := options.StatsigLoggerOptions.DisableAllLogging
log := &logger{
events: make([]interface{}, 0),
transport: transport,
tick: time.NewTicker(loggingInterval),
maxEvents: maxEvents,
disabled: disabled,
diagnostics: diagnostics,
options: options,
}
Expand Down Expand Up @@ -116,7 +119,7 @@ func (l *logger) logInternal(evt interface{}) {
l.mu.Lock()
defer l.mu.Unlock()

if l.options.DisableEventLogging {
if l.disabled {
return
}

Expand Down
2 changes: 1 addition & 1 deletion statsig.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ type Options struct {
OutputLoggerOptions OutputLoggerOptions
StatsigLoggerOptions StatsigLoggerOptions
EvaluationCallbacks EvaluationCallbacks
DisableEventLogging bool
}

type EvaluationCallbacks struct {
Expand All @@ -58,6 +57,7 @@ type StatsigLoggerOptions struct {
DisableInitDiagnostics bool
DisableSyncDiagnostics bool
DisableApiDiagnostics bool
DisableAllLogging bool
}

// See https://docs.statsig.com/guides/usingEnvironments
Expand Down

0 comments on commit 55ce0d8

Please sign in to comment.