GuidesAPI Reference
Submit Documentation FeedbackJoin Developer CommunityOptimizely GitHubOptimizely NuGetLog In

Customize logger

The logger logs information about your experiments to help you with debugging. You can customize where log information is sent and what kind of information is tracked.

You can use our SimpleLogger implementation out of the box.

To improve your experience setting up the SDK and configuring your production environment, we recommend that you pass in a logger for your Optimizely client. See the code example below.

import logging
from optimizely import logger
from optimizely import optimizely

# To set a log level choose one of the following:
# INFO: logging.INFO
# NOTSET: logging.NOTSET
# DEBUG: logging.DEBUG
# ERROR: logging.ERROR

# To define a minimum logging level pass it in during initialization.
# The example below shows a minimum logging level of INFO.
optimizely_client = optimizely.Optimizely(datafile, logger=logger.SimpleLogger(min_level=logging.INFO))

For finer control over your SDK configuration in a production environment, pass in a custom logger for your Optimizely client. A custom logger is a function that takes an argument, the level, and the message. See the code example below to create and set a custom logger.

import logging

def get_custom_logger(name, level=logging.INFO):
  """ Example of a custom logger.
    This function takes in two parameters: name and level and logs to console.
    The place to log in this case is defined by the handler which we set
    to logging.StreamHandler().
      name: Name for the logger.
      level: Minimum level for messages to be logged
  logger = logging.getLogger(name)

  if not logger.handlers:
    handler = logging.StreamHandler()
    formatter = logging.Formatter("Optimizely({}): %(levelname)s %(message)s".format(name))

  return logger

# Here we initialize the SDK with the custom logger.
optimizely_client = optimizely.Optimizely(datafile, logger=get_custom_logger('my_optimizely_logger'))

Log levels

The table below lists the log levels for the Python SDK.

Log Level



Events that cause the app to crash are logged.


Events that prevent feature flags from functioning correctly (for example, invalid datafile in initialization and invalid flag keys) are logged. The user can take action to correct.


Events that don't prevent feature flags from functioning correctly, but can have unexpected outcomes (for example, future API deprecation, logger or error handler are not set properly, and nil values from getters) are logged.


Events of significance (for example, decision started, decision succeeded, tracking started, and tracking succeeded) are logged. This is helpful in showing the lifecycle of an API call.


Any information related to errors that can help us debug the issue (for example, the feature flag is not running, user is not included in the flag rule) are logged.


Level set when a logger is created. Causes all messages to be processed when the logger is the root logger (or delegation to the parent when the logger is a non-root logger).

See also

Loggers return:

  • SDK lifecycle
  • flag decision messages

You can also view flag decision messages in the Reasons field of returned decision objects. For more information, see OptimizelyDecision

Source files

The language/platform source files containing the implementation for Python is