Disclaimer: This website requires Please enable JavaScript in your browser settings for the best experience.

The availability of features may depend on your plan type. Contact your Customer Success Manager if you have any questions.

Dev guideRecipesAPI ReferenceChangelog
Dev guideAPI ReferenceRecipesChangelogUser GuideGitHubDev CommunityOptimizely AcademySubmit a ticketLog In
Dev guide

Customize the GO SDK logger

Customize log information from the Optimizely Feature Experimentation Go SDK for debugging experiments.

The logger captures details about your experiments, making it easier for you to debug them. You can customize where the log information is stored and choose the types of data you want to track.

The default logger in the Go SDK logs to STDOUT. To disable or customize the logger, provide an implementation of the OptimizelyLogConsumer interface.

Custom logger implementation in the SDK

import "github.com/optimizely/go-sdk/pkg/logging" // for v2: "github.com/optimizely/go-sdk/v2/pkg/logging"

type CustomLogger struct {
}

func (l *CustomLogger) Log(level logging.LogLevel, message string, fields map[string]interface{}) {
}

func (l *CustomLogger) SetLogLevel(level logging.LogLevel) {
}

customLogger := New(CustomLogger)

logging.SetLogger(customLogger)

Setting the log level

You can also change the default log level from INFO to any of the other log levels.

import "github.com/optimizely/go-sdk/pkg/logging" // for v2: "github.com/optimizely/go-sdk/v2/pkg/logging"

// Set log level to Debug
logging.SetLogLevel(logging.LogLevelDebug)

Log levels

The following list shows the log levels for the GO SDK.

  • LogLevelError – Logs events that prevent feature flags from working properly, such as an invalid data file during initialization or incorrect feature keys. These issues require user intervention to fix.
  • LogLevelWarning – Logs events that do not prevent feature flags from working properly but may cause unexpected results, such as future API deprecation, improper logger or error handler settings, and nil values from getters.
  • LogLevelInfo – Logs key events to illustrate the lifecycle of an API call, such as when a decision or tracking starts and succeeds.
  • LogLevelDebug – Logs extra information related to errors that aid Optimizely in debugging, like when a feature flag is not running or a user is not included in a rollout.

Source files

The language or platform source files containing the implementation for Go is client.go.