Optimizely will be sunsetting Full Stack Experimentation on July 29, 2024. See the recommended Feature Experimentation migration timeline and documentation.

Dev GuideAPI Reference
Dev GuideAPI ReferenceUser GuideGitHubNuGetDev CommunitySumbit a ticketLog In
GitHubNuGetDev CommunitySumbit a ticket
These docs are for v2.0. Click to read the latest docs for v3.0.

Configure the logger

Steps to configure the go information from your experiments in Optimizely Full Stack Experimentation.

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.

In some SDKs, logging functionality is not enabled by default. See Default logging in each SDK below for a list of built-in logger support in each SDK.

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 examples below.

# android-logger.properties example (JSON)

# Java Core SDK
logger.com.optimizely.ab.Optimizely=DEBUG:Optly.core
logger.com.optimizely.ab.annotations=DEBUG:Optly.annotations
logger.com.optimizely.ab.bucketing=DEBUG:Optly.bucketing
logger.com.optimizely.ab.config=DEBUG:Optly.config
logger.com.optimizely.ab.error=DEBUG:Optly.error
logger.com.optimizely.ab.event=DEBUG:Optly.event
logger.com.optimizely.ab.internal=DEBUG:Optly.internal

# Android SDK
logger.com.optimizely.ab.android.sdk=DEBUG:Optly.androidSdk
logger.com.optimizely.ab.android.event_handler=DEBUG:Optly.eventHandler
logger.com.optimizely.ab.android.shared=DEBUG:Optly.shared
logger.com.optimizely.ab.android.user_profile=DEBUG:Optly.userProfile

# Disable most SDK logs by commenting all other lines and uncommenting below
# logger.com.optimizely.ab=ASSERT:Optly
using OptimizelySDK;
using OptimizelySDK.Logger;

ILogger logger = new DefaultLogger();
// Passing default logger
Optimizely optimizelyClient = new Optimizely(
	datafile: datafile,
	logger: logger
);
// Add dependency to gradle

implementation group: 'org.apache.logging.log4j', name: 'log4j-api', version: '2.20.0'
implementation group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.20.0'
implementation group: 'org.apache.logging.log4j', name: 'log4j-slf4j-impl', version: '2.20.0'

// Add log4j2.properties to your resources directory and configure as follows:

// Set the root logger level to INFO and its appender to the console
appender.console.type = Console
appender.console.name = STDOUT
appender.console.layout.type = PatternLayout
appender.console.layout.pattern = %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n

// Specify the loggers
rootLogger.level = debug
rootLogger.appenderRef.stdout.ref = STDOUT
const defaultLogger = require('@optimizely/optimizely-sdk/lib/plugins/logger');
const LOG_LEVEL = require('@optimizely/optimizely-sdk/lib/utils/enums').LOG_LEVEL;

/**
 * To set a log level choose one of the following:
 * 
 * NOTSET: LOG_LEVEL.NOTSET
 * DEBUG: LOG_LEVEL.DEBUG
 * INFO: LOG_LEVEL.INFO
 * WARNING: LOG_LEVEL.WARNING
 * ERROR: LOG_LEVEL.ERROR
 *
 * To define a minimum logging level pass it in during initialization.
 * The example below shows a minimum logging level of INFO.
 */
var optimizelyClientInstance = optimizely.createInstance({
  datafile,
  logger: defaultLogger.createLogger({
    logLevel: LOG_LEVEL.INFO
  }),
});
const defaultLogger = require("@optimizely/optimizely-sdk/lib/plugins/logger");
const LOG_LEVEL = require("@optimizely/optimizely-sdk/lib/utils/enums")
  .LOG_LEVEL;

/**
 * To set a log level choose one of the following:
 * 
 * NOTSET: LOG_LEVEL.NOTSET
 * DEBUG: LOG_LEVEL.DEBUG
 * INFO: LOG_LEVEL.INFO
 * WARNING: LOG_LEVEL.WARNING
 * ERROR: LOG_LEVEL.ERROR
 *
 * To define a minimum logging level pass it in during initialization.
 * The example below shows a minimum logging level of INFO.
 */
var optimizelyClient = optimizely.createInstance({
  datafile,
  logger: defaultLogger.createLogger({
    logLevel: LOG_LEVEL.INFO
  })
});
CustomLogger *customLogger = [[CustomLogger alloc] init];

OPTLYManager *manager = [[OPTLYManager alloc] initWithBuilder:[OPTLYManagerBuilder  builderWithBlock:^(OPTLYManagerBuilder * _Nullable builder) {
  builder.sdkKey = @"SDK_KEY_HERE";
  builder.logger = customLogger;
}]];

OPTLYLoggerDefault *optlyLogger = [[OPTLYLoggerDefault alloc] initWithLogLevel:OptimizelyLogLevelAll];
OPTLYManager *manager = [[OPTLYManager alloc] initWithBuilder:[OPTLYManagerBuilder  builderWithBlock:^(OPTLYManagerBuilder * _Nullable builder) {
  builder.sdkKey = @"SDK_KEY_HERE";
  builder.logger = optlyLogger;
}]];
use Monolog\Logger;
use Optimizely\Logger\DefaultLogger;

$optimizelyClient = new Optimizely($datafile, null, new DefaultLogger());

/**
 * To set a log level choose one of the following:
 * 
 * DEBUG: Logger.DEBUG
 * INFO: Logger.INFO
 * WARNING: Logger.WARNING
 * ERROR: Logger.ERROR
 * CRITICAL: Logger.CRITICAL
 *
 * To define a different minimum logging level pass it in during initialization
 * The example below shows a minimum logging level of WARNING and outputs
 * to standard out
 */

$optimizelyClient = new Optimizely($datafile, null, new
DefaultLogger(Logger::WARNING, "stdout"));
import logging
from optimizely import logger

optimizely_client = optimizely.Optimizely(
  datafile,
  logger=logger.SimpleLogger()
)

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

# To define a different minimum logging level pass it in during initialization
# The example below shows a minimum logging level of WARNING

optimizely_client = optimizely.Optimizely(
  datafile,
  logger=logger.SimpleLogger(min_level=logging.WARNING)
)
optimizely_client = Optimizely::Project.new(
  datafile,
  nil, # don't override the EventDispatcher
  Optimizely::SimpleLogger.new
)
let customLogger: CustomLogger? = CustomLogger()

let manager = OPTLYManager(builder: OPTLYManagerBuilder(block: { (builder) in
  builder?.sdkKey = "SDK_KEY_HERE"
  builder?.logger = customLogger
}))

let optlyLogger: OPTLYLoggerDefault? = OPTLYLoggerDefault(logLevel: OptimizelyLogLevel.all)

let manager = OPTLYManager(builder: OPTLYManagerBuilder(block: { (builder) in
  builder?.sdkKey = "SDK_KEY_HERE"
  builder?.logger = optlyLogger
}))

Log levels

The log levels vary slightly among SDKs but are generally as follows:

  • CRITICAL – Events that cause the app to crash are logged.
  • ERROR – Events that prevent experiments from functioning correctly (for example, invalid datafile in initialization and invalid experiment keys or event keys) are logged. The user can take action to correct.
  • WARNING – Events that do not prevent experiments 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.
  • DEBUG – Any information related to errors that can help us debug the issue (for example, experiment is not running, user is not in experiment, and the bucket value generated by our helper method) are logged.
  • INFO – Events of significance (for example, activate started, activate succeeded, tracking started, and tracking succeeded) are logged. This is helpful in showing the lifecycle of an API call.

Default logging in each SDK

  • Android – For the Android SDK, you can use our Android SLF4J logger. Logging verbosity can be controlled via the android-logger.properties file. This file can be placed in src/main/resources. You can also include a copy in src/release/resources with different settings for the build you release to the Play Store. Read about advanced configuration options.
  • iOS – You can use our default logger and configure OptimizelyLogLevelInfo. You can initialize it with any log level and pass it in when creating an Optimizely instance. You can also implement your own logger and pass it in the builder when creating an Optimizely instance.
  • Java – In the Java SDK, logging functionality is not enabled by default. To improve your experience setting up the SDK and configuring your production environment, we recommend that you include a SLF4J implementation in your dependencies. For the Java SDK, we require the use of an SLF4J implementation.

❗️

Warning

Due to a recently announced security exploit in the Log4J library, we recommend upgrading to version 2.16.0 or higher as soon as possible if you are using it alongside the SDK. View Apache's documentation on the Log4j vulnerability for more information.

  • JavaScript – By default, the JavaScript SDK uses our Logger implementation. You can also implement your own logger and pass it into the builder when creating an Optimizely instance. It's also possible to configure the log level threshold of the default logger without implementing your own logger. You can do so by passing the constructor an integer logLevel, and these are the possible levels.
  • PHP – You can use our Logger implementation out of the box, available on GitHub.
  • Python – You can use our SimpleLogger implementation out of the box, available on GitHub.
  • Ruby – You can use our SimpleLogger implementation out of the box, available on GitHub.